Good database design - where to store timestamp of events / function executions - mysql

Lets say I have some function get_inventory_report() that pulls a report from a server and updates values in my database.
I only want to get the report once every 24 hours so I need to somehow store the date and time that the report was pulled and then have a function like should_pull_inventory_report() which simply checks if the time that the report was last pulled is greater the set pull frequency.
I'm thinking the report pull frequency can be stored in a table called config, but what I'm not sure of is where or how to store the value for when the report was last pulled.
Essentially, I want to log the time and date of last successful executions of functions (report pulls, API requests) somewhere so that they can later be referenced to determine if enough time has passed that the function needs to be called again.

Related

Why SSRS are date parameters invalid when from a selection but not when "default"?

I have a selection of SSRS report where the client has requested that there is a different reporting range for each schedule e.g. The daily schedule run Daily reporting on sales for the past day, the Weekly schedule to report on previous week etc. I am trying to use one "sales" report to do this and have different options for the "Start" date as a parameter that can be selected. I have set these up as "Available" values rather than a "Default" with the following:
Daily = =DateAdd("D",-1,Today())
Monthly = =DateAdd("M",-1,Today())
I have set up a scheduled for this report to run using the parameter and selected "Daily" but when this runs I get the following error message:
The subscription contains parameter values that are not valid.
And then if I look at the subscription settings, the "Start" parameter is completely blank forcing me to select Daily or Monthly again. If I were to instead set it up as a default value using one of those parameter mappings then it works absolutely fine. Is there a way to have these optional parameters, or am I going to be forced to create different Daily/Weekly/Monthly reports each with their own default parameters for the start times.
Note: When I debug the report with those parameters it runs absolutely fine, the issue is with the scheduled versions not keeping the parameters.
If you have access to data-driven subscriptions with your SSRS version, you can pass in multiple dates, emails, etc. This allows you to send out different versions of the report in one subscription.
Another option would be to add another parameter with the Daily/Weekly/Monthly option. Then have the default date use this parameter value to determine the date value. Then you could have 3 subscriptions on the same report each with their own interval selected.
I hope one of these options will work for you.

Firestore Cloud Function Trigger only when path updates with new entire

I have a firestore database that looks like this
/entries/ ....
/users/{userid}...
a bunch of documents is being sent into ... of entries and userid contains on 8 docs of user profile information.
my problem is that the entries doc contains field hours and no relation to the user doc which contains the field weekly_capacity
I need to aggregate this the two fields hours/weekly capacity setting them to Full-time equivalency variable
But the Full-time equivalency needs to be accurate and this company FTE can change so it would need to calculate the FTE over various date even if the user changed their FTE status x number of times.
And the current app only fetched the entries when the user logins into the app, which can be whenever.
None of the API requests that I am using will give me a json that holds both weekly_capacity and hours on the same fetch. If every time a user logs into the app firestore calls the http to fetch all entries then how can I compare the hours field on the collection's entries to the weekly_capacity field
Just a little context: FTE = Full-time equivalency and is used to measure as a standard to see if an employee compares to there core commit hours they signed up for which is 40. SO if I agreed to work 40 and I work actually work 40 hours then I would be 1 whole FTE. If I worked 20 and I suppose to work 40 I am .5 FTE. The math is really simple it's just that in my situation the variable FTE can change any time and the app will allow the user to enter a range of dates fetching the total actual hours they worked and FTE letting them know how many hours they were supposed to work vs how many hours they actually worked. Since the variable changes, I need some way in firestore to track the change and aggregate correctly against the hours actually worked. To give an error example: let's say I changed my FTE from 1 to .7 on March 20th, I then want to generate a report of March 1 to March 30th stating my hours worked and FTE status meaning did I reach my goal. The kicker is that I can't fetch or merge the entries which hold the var hours and /users/ which hold the var weekly_capacity.
I don't even think a cloud function would solve the problem since entries are only fetched when the user logins in right?
I'm assuming the following for answering your question.
Requirement: To calculate FTE for a user when user's weekly_capacity is updated or user logs in.
Problems:
Some way in firestore to track the change.
Calculate FTE correctly according to the change.
Here's what I think will solve the problems.
Google Cloud Firestore supports listeners for the collections in which you store the data. So you can listen for any change in users collection and entries collection. This is how you can track the change.
To calculate FTE, when a change is made to weekly_capacity of user document or a new entry is made to entries collection you need to query both collections separately to get the records corresponding to the user affected. You can also use a collections-group query for this purpose but that depends on your database design.
Hope that helps.

Creating snapshot reports when subreports require parameters?

My situation is this - I'm using SSRS to create a "cascading" report set. The top-level report pulls all of the data from a table that capture our deployment/release activity. This data includes the property that executed a release, the organization to which that property belongs, the scheduled and actual start and end times of the release (and its constituent deployments), etc., etc., etc., and in the report I aggregate the data by time windows (Fiscal Year, then Quarter, then Month). So, at the top level, the user sees a report that shows how many deployments and releases we executed, how long they were expected to take, and how long they actually took, over the last twelve months, grouped, again, by Fiscal Year, then Quarter, than Month.
Now, the next level of detail the user wants to see is for a given month. When he or she clicks on the link to run that particular sub-report, they now get the same information (number of deployment, number of releases, scheduled and actual durations, etc.) grouped by organization, for that particular month.
Here's my dilemma - the initial report takes a LONG time to render. I would like to create snapshot report to reduce this render time, but my sub-report uses the Month from the top-level report as a parameter. In other words, when I click on the link to the sub-report, the Action setting in SSRS says to use the Month that I clicked on as a parameter to generate the sub-report, and the query in the sub-report filters off of that parameter with the following query condition:
AND FiscalQuarter IN (#Quarter)
So, the reporting works fine, but I am wondering - is there some way that I can get ALL of the data, for ALL quarters, into the sub-report in a snapshot report, and then just generate that snapshot but filtered out for the quarter value that I pass from the top-level report as a parameter?
yes you can, by creating a snapshot for sub report for all values.
and the parameter defined on the subreport should be a dataset filter not a query parameter .
Now when you pass parameter from main report to subreport , it will filter it accordingly on the sub report snapshot without having to execute the costly sql
Alas, reporting services does not provide what you need. Caching reports will create a cached version of the report per distinct combination of parameter values, and a similar situation holds for cached datasets.
You have roughly two options left it seems:
Use a cached dataset, have the subreport use the cached dataset but only use the parameter to filter the data once it's retrieved (e.g. in a tablix)
Resort to a more database-oriented caching-like or performance enhancing strategy such as for example indexed views for your queries

How to calculate the difference between times and store the result in a mySQL database (VB.NET)?

I'm quite new to VB and i'm working on a project to record the details of employees clocking in and clocking out. I want to know how to make it so when the 'clock in' button is clicked the time will start recording and when the 'clock out' button is pressed the time will stop recording. Also once clock out is clicked the hours in between clock in and clock out will be recorded and stored into a mySQL database.
This information will be outputted onto a DataGrid showing the time and date of when the employee has clocked in.
Then the amount of hours will be multiplied by a pre-written hourly wage .. which is already stored inside one of the tables in my mySQL database.
Any help would be appreciated.
You should store the event instead of the result.
Store the clock-in time as well as a row for the clock-out time.
Then you will need a procedure either on your database or in the application that will iterate over the rows and match clock-ins to clock-outs.
This approach will let the application crash/terminate and restart without losing data.
Alternatively you could put the clock-in and out in the same record (different columns), and just insert the clock-out into the first row that matched employee and null clock-out.
I would have the clock In button fire an event in the program that created a record for the employee ID I'm assuming you have at that time.
Then once the clock out button is clicked you would fire an event that would go out to your database and pull in the first record it found with the employee ID you are looking for, a valid clock in time and a null for the clock out time. If the program didn't find something that matched all that criteria you would have to handle that however you wanted (I would do the lookup when the employee logged in or whatever and only allow them access to the clock in button if there was no record present and only allow them to use the clock out button if there was a record found for their ID).
Once you have that record in memory you should set the clock out time and calculate the difference using the clock in time that was written to the database earlier.
I would use a stored procedure in the database to handle adding/updating/managing the record and do all the calculations and whatever else you want to do at the time of the clock in/out inside the program itself. But I think its all just preference as far as where the actual processing takes place is concerned.
The most obvious reason for this is that the program can be shut down in between clock in's and clock out's without losing anything at all. If you try to keep track of it all in memory you will lose all your clock in's once the program is shut down for whatever reason(closed manually/"End Task"ed through task manager/unhandled error).

How to create multiple Snap shots in ssrs report

I have read like, we can create multiple snapshot for a SSRS report.But we have to create a default value as a filter if exist.So my question is,at first we add a default value in parameter and deploy the report and set the snap shot option.Then what is meant by multiple snap shots?At a time we have only one default value right?So multiple snapshot means same data will be there for all snapshot right? Also,How can we create mutiple snapshot?
Snapshots are meant for using the same default parameters and having them run on a schedule. That would be useful for a report where the data changes every day and you want to keep a snapshot from every day. Not useful if your data never changes and you want to use different parameter values.
The other option is to use a "Cache refresh plan". You can set up different schedules and different parameter values for these and set it to cache a temporary copy of the report that expires after a day or whatever you like (in minutes).
I use the second option for a report which takes about 30 seconds to run. This is too long for the user (Senior Manager) so I have it set to run at 7am every day and then just show that same cached report to the manager all day no matter how many times the report is run.