I've been working on a quick app to do a little math from user inputs that gives me the total of units left to produce, what I'd like is to be able to display what time it would be finished. The issue I'm having is figuring out how to add the number from the hours left to the local time and receive an end time. I'm working in Kotlin.
Related
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.
I have a batch job that runs once per day.
At the end of the job I submit a meter metric with a count of the items processed.
I want to alert if one day this metric is not updated.
On http://metrics.librato.com the maximum time I can check "not reported for" when creating an alert is 60 minutes.
I thought maybe I can create a composite metric and take the avg rate of change over the past 24 hours, and alert if that reaches zero.
I've been trying:
derive(s("my.metric", "%", {function:"sum", period:"86400"}))
However it seems that, because I log only a single event, above quite small values of period (~250s) my rate of change simply drops to zero ...I guess the low frequency means my single value is completely lost by the sampling.
Maybe I am using the wrong tool for the job...
Is there a way to achieve this in Librato?
There currently is not a way to achieve this as composite metrics are subject to the 60 minute limitation of alerts as well (as of 5/15/2015). You may need to look into configuring the metric (or a similar metric) to report within the 60m time range if possible.
I am using Informix database for storing data.Iam continuously running my application from 08:00AM to 04:00pm.I want to take the average in every half hour from 08:00AM till end and generate report.I am using VBA script in my application.
If any one know how to take average in every half hour and generate report by using script.
Is this an Informix doubt, or a VBA one?
If you mean "how can I get an average in Informix", you can use (as in several other database engines, AVG function).
I have an access query that will run to calculate the total activity in a location at a specified time. Is there a way to run this over a range of dates and return the results using SQL or should I write a form to run the query various with dates from code?
To make matters slightly more complicated, the query is also dealing with radioactive decay, correcting each item to its current activity at the time requested - although this can probably be ignored for testing.
Finally, on a slightly unrelated note, items and arrive and leave a location at any time, but it is unfeasible to have data points for each second of every day, so I am using three hour intervals as a compromise - as radioactive decay follows an equation, anyone have a better way of doing this (so that data is plotted as soon as an item arrives, otherwise the decay from the arrival time and plotted interval can effect my result a lot) or is this the best I am likely to manage?
Current SQL for single date:
SELECT FORMAT(SUM(Items.Activity*(Exp(-(0.693*(dDate-Items.MeasuredOn)/Nuclides.HalfLife)))), '#,##0.00') AS CurrentActivity
FROM Nuclides INNER JOIN ((Locations INNER JOIN (Items INNER JOIN ItemLocations ON Items.ItemID = ItemLocations.ItemID) ON Locations.LocationID = ItemLocations.LocationID) INNER JOIN LocationLimits ON Locations.LocationID = LocationLimits.LocationID) ON (Nuclides.Nuclide = Items.Nuclide) AND (Nuclides.Nuclide = LocationLimits.Nuclide)
WHERE (((ItemLocations.LocationID)=lLocationID) AND ((ItemLocations.RecieptDate)<dDate) AND ((ItemLocations.DisposalDate)>dDate Or (ItemLocations.DisposalDate) Is Null));
Could no figure out how to solve in the way I initially imagined, so solved as follows instead:
User inputs a date range for the time period they want to view data for.
One query to return single list of all dates when an event happened (date item added, date item removed)
Using set time intervals (now one hour) activity calculated at the time until an event time is reached. At event time activity is calculated for half a second before the event occurred and the time of the event itself. We then continue with our hour intervals until the next event.
After final event keep calculating at the interval until the end time is reached.
This works quickly enough to not be a problem for the user, and the graph is as smooth as it needs to be. FYI activity is also calculated half a second before events to give a vertical slope on the line, otherwise it will be slanted from the previous point (potentially an hour or more of time).
I have a program that reports how many times a customer has visited between a certain our of the day. In this case, the program runs each day, to find out how many customers came in between the hours of 6 and 7. The problem I'm running into is I also need to keep a running tally of the number of customers visted between the hours. So I need the output to look like:
Today: 5
Total: 5
Today: 5
Total: 10
Today 5
Total 15
I can store the info in an XML file, but I have 16 different locations I'm tracking so that's a lot of writing, and reading from an xml file, so I assume there is a better way to handle this? I basically need the program to load the value of the "total" which is Today, plus previous days.
I fill the values like this:
firsthour = ds.Tables(0).Rows(i).Item(x)
secondhour = ds2.Tables(0).Rows(i).Item(x)
Percentage = Math.Round(ds2.Tables(0).Rows(i).Item(x) / ds.Tables(0).Rows(i).Item(x) * 100, 2)
firsthourtotal = ds.tables(0).Rows(i).item(x)
secondhourtotal = ds2.tables(0).Rows(i).item(x)
Obviously, I need the Fisthourtotal, secondhourtotal, to be stored for each of the 16 results in the array, to be accessed each day when the program runs.
Probably not the best way but....
If I was doing it I would use My.Settings and use the System.Collections.Specialized.StringCollection type for the situation described.
Nice and easy to read and write to, just remember to My.Settings.Save after writing to it otherwise it will wait till you close the application before updating the record!