Working with the new Notes 9.x calendar functions but having trouble with recurring meetings. Want to list all calendar events between two datetime values but recurring events show the first event but not the event that falls in my date range.
Programming is like this:
Pid = "DAETNYR"
starttime = "2014-03-14T6:00:00Z"
endtime = "2014-03-14T19:00:00Z"
Set PersonDoc = NabHelp.SearchForPersonDoc(Pid)
server1 = PersonDoc.MailServer(0)
server1 = "TestServer1/IA/Servers/USA"
file1 = PersonDoc.MailFile(0)
Set UserMailDb = New NotesDatabase(server1, file1)
Set cal = Session.getCalendar(UserMailDb)
Set StartDate = New NotesDateTime( StartTime )
Set EndDate = New NotesDateTime( EndTime )
ForAll cale In cal.getEntries(StartDate, EndDate)
calestr = cale.ReadRange(StartDate, EndDate)
i = InStr(calestr, "RECURRENCE-ID:")
stop
If i > 0 Then
recurid = Mid$(calestr, i + 14, 16)
End If
If recurid = "" Then
Set caldoc = cale.Getasdocument()
Else
Set caldoc = cale.Getasdocument(0, recurid)
End If
End ForAll
Do I read through calestr to find each recurid and test it against the date range? Any ideas?
The object model is a little tricky. A NotesCalendarEntry is a single object representing all the instances of a recurring event. As your sample shows, you can get the document associated with a single instance [cale.Getasdocument(0, recurid)], but you need to know the recurrence ID first.
The problem is NotesCalendar.getEntries() doesn't tell you anything about which recurrence ID falls in the given date range. (By the way, your sample includes this: cale.ReadRange(StartDate, EndDate). I'm not sure what that does since there is no ReadRange() method for NotesCalendarEntry.)
It would be better for you to use NotesCalendar.readRange(). That returns an iCalendar string listing all the events in the range including the recurrence IDs of specific instances. For example, here is some sample output:
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART:20140314T130000Z
DTEND:20140314T140000Z
TRANSP:OPAQUE
RECURRENCE-ID:20140314T130000Z
DTSTAMP:20140314T121932Z
SEQUENCE:0
CLASS:PUBLIC
SUMMARY:Two week sabbatical
LOCATION:Off site
UID:A56ADC092EA2323285257C75006B2B3F-Lotus_Notes_Generated
X-LOTUS-SUMMARYDATAONLY:TRUE
X-LOTUS-APPTTYPE:0
END:VEVENT
BEGIN:VEVENT
DTSTART:20140315T130000Z
DTEND:20140315T140000Z
TRANSP:OPAQUE
RECURRENCE-ID:20140315T130000Z
DTSTAMP:20140314T121932Z
SEQUENCE:0
CLASS:PUBLIC
SUMMARY:Two week sabbatical
LOCATION:Off site
UID:A56ADC092EA2323285257C75006B2B3F-Lotus_Notes_Generated
X-LOTUS-SUMMARYDATAONLY:TRUE
X-LOTUS-APPTTYPE:0
END:VEVENT
END:VCALENDAR
That shows two event instances with the same UID, but different recurrence IDs. Of course, this is just the summary data for each instance. You can read the instance details like this (in Java):
NotesCalendarEntry entry = cal.getEntry("A56ADC092EA2323285257C75006B2B3F-Lotus_Notes_Generated");
String instanceOne = entry.read("20140314T130000Z");
String instanceTwo = entry.read("20140315T130000Z");
All of the above assumes you can parse the iCalendar format returned by NotesCalendar.readRange(). That's easy in Java with a library like ical4j. It's a bit more difficult with LotusScript, but it's worth the effort. The new NotesCalendar classes make heavy use of iCalendar.
Related
I have an episode-id and from this I want to derive the series.
How can I do that?
This is what I tried:
ia = IMDb()
movie = ia.get_movie(id)
if movie['kind'] == "episode":
series = movie['episode of']
print(series)
This gives me only the series title, allthough the documentation says, 'episode of' gives in addition the id of the series.
The series object stored in the 'episode of' key is an instance of the Movie class, so you can access the series ID using:
imdbID = series.movieID
You can also update the information of the Movie instance so that more information (besides title and ID) are collected, with something like:
ia.update(series)
I'm new to web development and rails, and I'm trying to construct a query object for my first time. I have a table Players, and a table DefensiveStats, which has a foriegn-key player_id, so each row in this table belongs to a player. Players have a field api_player_number, which is an id used by a 3rd party that I'm referencing. A DefensiveStats object has two fields that are relevant for this query - a season_number integer and a week_number integer. What I'd like to do is build a single query that takes 3 parameters: an api_player_number, season_number, and week_number, and it should return the DefensiveStats object with the corresponding season and week numbers, that belongs to the player with api_player_number = passed in api_player_number.
Here is what I have attempted:
class DefensiveStatsWeekInSeasonQuery
def initialize(season_number, week_number, api_player_number)
#season_number = season_number
#week_number = week_number
#api_player_number = api_player_number
end
# data method always returns an object or list of object, not a relation
def data
defensive_stats = Player.where(api_player_number: #api_player_number)
.joins(:defensive_stats)
.where(season_number:#season_number, week_number: #week_number)
if defensive_stats.nil?
defensive_stats = DefensiveStats.new
end
defensive_stats
end
end
However, this does not work, as it performs the second where clause on the Player class, and not the DefensiveStats class -> specifically, "SQLite3::SQLException: no such column: players.season_number"
How can I construct this query? Thank you!!!
Player.joins(:defensive_stats).where(players: {api_player_number: #api_player_number}, defensive_stats: {season_number: #season_number, week_number: #week_number})
OR
Player.joins(:defensive_stats).where("players.api_player_number = ? and defensive_stats.season_number = ? and defensive_stats.week_number = ?", #api_player_number, #season_number, #week_number)
I am reading about DDD and I have learned that Value Object is immutable, if you want to change it, you will have to create a new one.
I have just read the information on How are Value Objects stored in the database? , it works well for Address class and I also read https://cargotracker.java.net/ and https://gojko.net/2009/09/30/ddd-and-relational-databases-the-value-object-dilemma/. But I want to do something different .
I am working on a billing system , it has 4 tables/classes
TPerson - fields: id_person, name -> <<Entity>>
TMobile - fields: id_mobile, number -> <<Entity>>
TPeriod - fields: id_period, id_person, id_mobile, begin_date, end_date -> <<Value Object>> (I think, because the dates can be change)
TCall - field: id_call, id_period, etc... -> <<Value Object>>
The table TCall has many records, if I change the period record dates (Value Object, table TPeriod) it will create another Object Period then id_period will change(delete, insert a record) , but the foreign key in table TCall will be violated. How Could I implement the period class ? if i implement as a value object , it will be immutable and turns out I will not be able to change anything whatsoever.
Thanks,
Fernando
if it's a value object you don't have a period table/id.
A value object is just a grouping of certain fields. For example a call might have a start time, an end time, and then you could create a Duration Value object with starttime and end time from the call table. In your java code it would be then more convenient to talk about the call duration instead of the start/end time separately.
However, it certainly could make sense to make period an entity, but then period 201601 probally always have the same start/end time and you wouldn't need to make changes to it. And if you did you make changes to the entity directly and keeping the ids in tact.
Thank for your help,
I have this situation:
TPerson - fields: id_person = 1 , name = "John"
TMobile - fields: id_mobile = 100, number "555-0123"
TPeriod - fields: id_period = 1000, id_person = 1 , id_mobile = 1, begin_date = "2016-01-01", end_date = "2049-12-31"
TCall - field: id_call = 1, id_period = 1000
The period is a relation between TPerson and TPeriod, in this example John has a mobile between "2016-01-01" and "2049-12-31". On the table TCall there are John's calls record, but if i replace the period (TPeriod table) end_date to "2016-02-01", from my understanding the end_date will be inconsistent, it turns out i cann't replace because it's a value object, not a entity. I considered to implement like this.
// Create a class DatePeriod
public class DatePeriod {
private final begin_date;
private final end_date;
DatePeriod() {}
public static DatePeriod of(Date begin_date, Date end_date) {
this.begin_date = begin_date;
this.end_date = end_date;
}
// implement equals / hashcode...
}
// Period class
public class Period {
int id;
// others mappings id_person / id_mobile
DatePeriod datePeriod;
}
Still, i will have to update datePeriod attribute
Thank you for your attention to this matter
I have one model to make my Catalog like this
class Product(models.Model):
item = models.CharField(max_length=10)
description = models.CharField(max_length=140)
unit = models.CharField(max_length=5)
expiration= models.IntegerField(default=365) # Days after admission
expiration_warning= models.IntegerField(default=30) # Days before expiration
...
and I have my Inventory like this:
class Inventory(models.Model):
product = models.ForeignKey(Product)
quantity= models.DecimalField(default=0, decimal_places=2, max_digits=10)
admission = models.DateTimeField(auto_now_add=True)
...
Now I want to retrieve all Inventory objects that its expiration date is upcoming or has been reached.
With a RAW SQL query, it will be something like:
SELECT product,quantity,admission,expiration,expiration_warning
FROM Inventory as I JOIN Product as P on I.product=P.id
WHERE DATEADD(day,(expiration_warning*-1),DATEADD(day,expiration,admission))<=GETDATE()
I haven't tried this query yet, it is just an example
I want to achieve this using Django query syntax, can you help me please?
Maybe something like this can achieve what you need:
from datetime import datetime, timedelta
expiring_inventory = []
expired_inventory = []
for inventory in Inventory.objects.select_related('product').all(): # 1 query
p = inventory.product
expire_datetime = inventory.admission + timedelta(days=p.expiration)
expiring_datetime = expire_datetime - timedelta(days=p.expiration_warning)
if expiring_datetime <= datetime.now() < expire_datetime: # not quite expired
expiring_inventory.append(inventory)
if expire_datetime <= datetime.now(): # expired
expired_inventory.append(inventory)
You can read more about Query Sets in the django docs.
I have a Coupon model that has some fields to define if it is active, and a custom manager which returns only live coupons. Coupon has an FK to Item.
In a query on Item, I'm trying to annotate the number of active coupons available. However, the Count aggregate seems to be counting all coupons, not just the active ones.
# models.py
class LiveCouponManager(models.Manager):
"""
Returns only coupons which are active, and the current
date is after the active_date (if specified) but before the valid_until
date (if specified).
"""
def get_query_set(self):
today = datetime.date.today()
passed_active_date = models.Q(active_date__lte=today) | models.Q(active_date=None)
not_expired = models.Q(valid_until__gte=today) | models.Q(valid_until=None)
return super(LiveCouponManager,self).get_query_set().filter(is_active=True).filter(passed_active_date, not_expired)
class Item(models.Model):
# irrelevant fields
class Coupon(models.Model):
item = models.ForeignKey(Item)
is_active = models.BooleanField(default=True)
active_date = models.DateField(blank=True, null=True)
valid_until = models.DateField(blank=True, null=True)
# more fields
live = LiveCouponManager() # defined first, should be default manager
# views.py
# this is the part that isn't working right
data = Item.objects.filter(q).distinct().annotate(num_coupons=Count('coupon', distinct=True))
The .distinct() and distinct=True bits are there for other reasons - the query is such that it will return duplicates. That all works fine, just mentioning it here for completeness.
The problem is that Count is including inactive coupons that are filtered out by the custom manager.
Is there any way I can specify that Count should use the live manager?
EDIT
The following SQL query does exactly what I need:
SELECT data_item.title, COUNT(data_coupon.id) FROM data_item LEFT OUTER JOIN data_coupon ON (data_item.id=data_coupon.item_id)
WHERE (
(is_active='1') AND
(active_date <= current_timestamp OR active_date IS NULL) AND
(valid_until >= current_timestamp OR valid_until IS NULL)
)
GROUP BY data_item.title
At least on sqlite. Any SQL guru feedback would be greatly appreciated - I feel like I'm programming by accident here. Or, even better, a translation back to Django ORM syntax would be awesome.
In case anyone else has the same problem, here's how I've gotten it to work:
Items = Item.objects.filter(q).distinct().extra(
select={"num_coupons":
"""
SELECT COUNT(data_coupon.id) FROM data_coupon
WHERE (
(data_coupon.is_active='1') AND
(data_coupon.active_date <= current_timestamp OR data_coupon.active_date IS NULL) AND
(data_coupon.valid_until >= current_timestamp OR data_coupon.valid_until IS NULL) AND
(data_coupon.data_id = data_item.id)
)
"""
},).order_by(order_by)
I don't know that I consider this a 'correct' answer - it completely duplicates my custom manager in a possibly non portable way (I'm not sure how portable current_timestamp is), but it does work.
Are you sure your custom manager actually get's called? You set your manager as Model.live, but you query the normal manager at Model.objects.
Have you tried the following?
data = Data.live.filter(q)...