Get the latest events of a specific type from a specific device - cumulocity

Is there a way to get the latest event of a specific type from a specific device? So far I queried all events via myURL/event/events?source=<<ID>>&type=<<type>>.
Or is there a way to get a collection of events ordered by their creationTime? This could solve my problem too
In the documentation I only found parameters like dateFrom and dateTo. But what if I don't know the time range of the last event?

The syntax is: /event/events?type={type}&source={source}.
For more information on the available endpoints:
GET /platform

Answer from the support-team:
currently there is no way to revert the order of events. Besides
dateFrom and dateTo you can also use creationFrom and creationTo. This
will take the creationTime (server side timestamp when event was
created) instead of the time (that is send within the event) But the
order will still be oldest -> newest.
Best approach currently would be to use a good estimated time range
(so you don't end up with 0 events in the response) where the
dateTo/creationTo is in the future. If you add to the query params
withTotalPages=true the result will give you the total pages in the
statistics part.
Knowing the total pages you can you can do the query again but with
currentPage=XX instead of withTotalPages=true and take the last
element.
We have this functionality on measurements and audits where you can
add the parameter revert=true. I will add an improvement that we
extend this to the other APIs but at the moment you are limited to the
workaround.

You can just only set the dateFrom parameter and the pageSize to 1 like so: &pageSize=1&dateFrom=1970-01-01. As of September 2017, this returns the most recent event.

Related

Laravel where clause based on conditions from value in database

I am building an event reminder page where people can set a reminder for certain events. There is an option for the user to set the amount of time before they need to be notified. It is stored in notification_time and notification_unit. notification_time keeps track of the time before they want to be notified and notification_unit keeps track of the PHP date format in which they selected the time, eg. i for minutes, H for hours.
Eg. notification_time - 2 and notification_unit - H means they need to be notified 2 hours before.
I have Cron jobs running in the background for handling the notification. This function is being hit once every minute.
Reminder::where(function ($query) {
$query->where('event_time', '>=', now()->subMinutes(Carbon::createFromFormat('i', 60)->diffInMinutes() - 1)->format('H:i:s'));
$query->where('event_time', '<=', now()->subMinutes(Carbon::createFromFormat('i', 60)->diffInMinutes())->format('H:i:s'));
})
In this function, I am hard coding the 'i', 60 while it should be fetched from the database. event_time is also part of the same table
The table looks something like this -
id event_time ... notification_unit notification_time created_at updated_at
Is there any way to solve this issue? Is it possible to do the same logic with SQL instead?
A direct answer to this question is not possible. I found 2 ways to resolve my issue.
First solution
Mysql has DATEDIFF and DATE_SUB to get timestamp difference and subtract certain intervals from a timestamp. In my case, the function runs every minute. To use them, I have to refactor my database to store the time and unit in seconds in the database. Then do the calculation. I chose not to use this way because both operations are a bit heavy on the server-side since I am running the function every minute.
Second Solution
This is the solution that I personally did in my case. Here I did the calculations while storing it in the database. Meaning? Let me explain. I created a new table notification_settings which is linked to the reminder (one-one relation). The table looks like this
id, unit, time, notify_at, repeating, created_at, updated_at
The unit and time columns are only used while displaying the reminder. What I did is, I calculated when to be notified in the notify_at column. So in the event scheduler, I need to check for the reminders at present (since I am running it every minute). The repeating column is there to keep track of whether the reminder is repeating or not. If it is repeating I re-calculate the notify_at column at the time of scheduling. Once the user is notified notify_at is set to null.

How do you get the ticket created date in trac?

I want to play with some really simple queries for a report, but I want to group everything by the creation date. The problem I am having is that time exists in the database, but not the date. From searching around in trac-related resources, it looks like I need to install trac.util.datefmt to be able to extract this information from datetime(time). I can find the API documentation for trac.util.datefmt, but not a download link to get the .egg.
Am I going in the right direction? If I can do what I need (i.e. get the creation month/day/year) without a plugin, what column do I use? I don't see anything else in the schema that is reasonable. If I do need trac.util.datefmt, where do I download it from? And if I really need a different plugin, which one should I be using?
I'll assume Trac >= 1.0. The time column is unix epoch time: the number of seconds that have elapsed since January 1st 1970. You can divide the value by 1e6 and put the value in a converter to see an example of extracting the datetime from the time column. trac.util.datefmt is part of the egg that ships with Trac, but since you are working with reports it doesn't sound like you need to know more about that function to accomplish your aim.
In a Trac report the time column will be automatically formatted as a date. You can look at the default report {1} as an example. I'm not sure how you intend to group by creation date. Do you wish to group tickets created in a certain datetime range?

kibana/elasticsearch advanced query

I am sending events with logstash to an elasticsearch database. An event is structured like this:
timestamp:2014-04-04 12:00:00 name:'leo' time:10
timestamp:2014-04-04 12:00:30 name:'john' time:15
...
...
In the Kibana interface, I am able to display some graphs; for example, the mean time of the timestamp.
Since logstash is continuously sending events, I would like to display the latest event sent in real time. Is it possible to write a query which will only return the latest event, using the timestamp field? I don't want to touch Kibana's "time filter"
Thanks in advance for your help
The easiest way to see the latest entry is to sort by timestamp, descending, in the 'Events' section of the Kibana interface. If you really only wanted to see one result, you could adjust the paging settings to only return one page consisting of one entry, and set the 'Auto-refresh' to a short interval (the shortest is 5s, I believe.)
Here's the Kibana documentation - might help.

Selecting specific joined record from findAll() with a hasMany() include

(I tried posting this to the CFWheels Google Group (twice), but for some reason my message never appears. Is that list moderated?)
Here's my problem: I'm working on a social networking app in CF on Wheels, not too dissimilar from the one we're all familiar with in Chris Peters's awesome tutorials. In mine, though, I'm required to display the most recent status message in the user directory. I've got a User model with hasMany("statuses") and a Status model with belongsTo("user"). So here's the code I started with:
users = model("user").findAll(include="userprofile, statuses");
This of course returns one record for every status message in the statuses table. Massive overkill. So next I try:
users = model("user").findAll(include="userprofile, statuses", group="users.id");
Getting closer, but now we're getting the first status record for each user (the lowest status.id), when I want to select for the most recent status. I think in straight SQL I would use a subquery to reorder the statuses first, but that's not available to me in the Wheels ORM. So is there another clean way to achieve this, or will I have to drag a huge query result or object the statuses into my CFML and then filter them out while I loop?
You can grab the most recent status using a calculated property:
// models/User.cfc
function init() {
property(
name="mostRecentStatusMessage",
sql="SELECT message FROM statuses WHERE userid = users.id ORDER BY createdat DESC LIMIT 1,1"
);
}
Of course, the syntax of the SELECT statement will depend on your RDBMS, but that should get you started.
The downside is that you'll need to create a calculated property for each column that you need available in your query.
The other option is to create a method in your model and write custom SQL in <cfquery> tags. That way is perfectly valid as well.
I don't know your exact DB schema, but shouldn't your findAll() look more like something such as this:
statuses = model("status").findAll(include="userprofile(user)", where="userid = users.id");
That should get all statuses from a specific user...or is it that you need it for all users? I'm finding your question a little tricky to work out. What is it you're exactly trying to get returned?

Repeated events in Eventbrite API

I noticed that when I search future events via event_search method, sorted by date, that first events in result-set have start date from past. Problem with these events is that they are repeatable events (e.g. weekly), but API does not return events' recurrence type (daily, weekly, monthly, other). Method should at least return next event start date and recurrance type.
Hidden feature:
Add "display=repeat_schedule" to your API requests to reveal a series of start_date, end_date pairs for each repeating instance.
Unfortunately, Eventbrite's "repeating events" feature (available on their website) is not totally compatible with their API services:
Most storage models have an associated identifier or 'handle' to reference each asset or resource. In REST-speak these identifiers are known as 'resource ids'.
Eventbrite's repeating events share a single event id, and they include a string that describes the schedule when they repeat.
The head of the chain of repeating events is returned, with a "repeats" attribute that is set to "yes". And, the "repeat_schedule" attribute should now be present on all repeating events.
The string that is revealed will have a different format depending how the event is configured to repeat:
Daily repeating events:
"daily-4-07/26/2012" - every fourth day, from the date/time of the
start_date until 2012-07-26.
"daily-mf-07/26/2012" - every Monday
through Friday, from the start_date day/time until "2012-07-26"
Weekly repeating events:
"weekly-3-Y,N,N,N,N,N,N-09/16/2012" - every 3rd week, on each day marked with a "Y" until "2012-09-16"
Monthly repeating events:
"monthly-2-10-06/30/2012" - every second month, on the 10th day of the month until "2012-06-30"
"monthly-2-second/sat-06/30/2012" - every second month, on the second Saturday of that month, until "2012-06-30".
Custom repeat schedule (not fully supported):
"custom-3199915" - This format is really rare. Unfortunately, these events can not be easily summarized using a single string.
This bug needs to be fixed by EventBrite
However Would this work has a temp workaround? I would work in some examples I have seen.
I make request for events on March 17, 2012
I get back a past date
<repeats>yes</repeats>
<start_date>2011-12-04 09:30:00</start_date>
<end_date>2011-12-04 10:30:00</end_date>
Can I assume this is a repeating event that occcurs on March 17, 2012
at the same times?
There's a new endpoint that can be used to fetch all the events that are part of a series, the only values required are: OAuth Token and the event_series_id which is the parent event ID or the ID of the event where the series was created.
This is the endpoint:
GET - https://www.eventbriteapi.com/v3/series/{event_series_id}/events/
Replace {event_series_id} with your event series ID.
More details at: https://www.eventbrite.com/platform/api#/reference/event/list/list-events-by-series