Firestore Cloud Function Trigger only when path updates with new entire - function

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.

Related

Database Size Management

I am in the final stages of building my website and I am getting a little nervous that I am doing something wrong with my database.
I am building a Laravel/mysql site that allows users to add events. So I have an Event database. I allow users to choose dates for their event for next six months. That means one Event can have around 180 event dates which I save to a separate database called Shows. Each of those show dates can have tickets and the prices(vip, general etc) in a Ticket database. That means for just one event, it could create a huge number of entries.
event(1) -> show on every day(180) -> 5 ticket types(900 entries in my tickets database)
As far as I can tell this is the correct way to do it, but it seems like my Ticket database is going to get massive quickly. I will be using Elastic Search to filter through the data.

How to effectively store data of varying time framces

I have a form that captures production data for a certain process. When a employee enters production numbers, currently I am not sure what the time frame for the production numbers are.
E.g. Employee A enters a production number of 50 on 2017/10/02. This 50 represents the production of 1 day (2017/10/01). Now, employee B enters 550 on 2017/10/03, but this represents production for the week of 2017/09/24 to 2017/10/01.
Now, we know that various employees will be providing data of different time frames, but I'm trying to figure out the best way to manage this. I capture data using a Excel sheet with VBA, and then transfer it to a SQL database. Currently, in the database we use GROUP BY to get all data related to a certain month. So if the timestamp of the data is in September, all September data will be summed and the total used as the September total to date. However, this does not answer two key points:
If data for September is entered in October.
If data is entered that duplicates a period for the employee that was entered earlier.
What is the best way of managing this? I can change my capturing form and the way we manage data in the database.
EDIT and more information:
The information I want to capture consists of production numbers from various production areas entered by an employee. So for example, site A will have 3 sub-sites. These sub-sites will each have a production achieved, target for the period and forecasted production number.
Timestamp: Site: Sub-site: Production: Target: Forecast:
2017/10/01 PlaceA Line1 200 250 230

Does the Socrata SODA API support getting a list of dates on which the dataset was modified?

Does the Socrata SODA API support a method to query out all the dates a dataset has been updated? Basically a changelog for the dataset that has an object for every modification/update to a dataset.
There is an existing question that asks for the last modified date (you can get it through the "/data.json API available on all Socrata-powered sites".
There is also a method to get the modified dates of individual rows using System Fields and the :update_at field. But this is incomplete, a data provider might update every row each time. This means there is no guarantee that we are really getting back a history of modifications, just the top layer of modification on each row.
I'm looking for the complete list of modification dates, at least. We are trying to get a sense of activity on datasets and we need to know how often they are being updated.
Unfortunately, Max, we don't offer what you're looking for. We've got the last time the dataset and metadata were modified, but not a changelog of every single time that there was a change.
A surprisingly large number of datasets change very frequently, as often as every 5 minutes.

Creating an MS Access query based on system, status, and date

I am just learning Access and have been tasked with creating a database for system access. We need a report that shows what systems have been in a pending status for 0-30 days, 31-60 days, 61-90 days, and 91+ days. I am soooo close to getting this but I’m at a dead end. For the examples below I will just use NFC and eOPF as the systems (there are five systems in all).
So the report would read like this:
Pending Date...0-30...31-60...61-90...90+
NFC....................1.........4..........8........1
eOPF..................2.........5..........1........0
I have the table setup with a status field for each group (i.e. NFC Status = “Pending” or “Complete”)
I have another field that has a date submitted (i.e. NFC Submitted Date = “XX/XX/XXXX”)
This is what I have done. I am only sharing this to give an idea of the direction I was heading. If there is a better way please let me know.
I created two quires (NFC Requests & eOPF Requests)
The first row field in the query is the status (i.e. NFC Status) with Criteria =”Pending”
The second row is the 0-30 days with the field of NFC 0 - 30 Days: Sum((IIf([Systems Access - Table]![NFC Form Date Submitted]>Date()-31,1,0)))
The third row is NFC 31 - 60 Days: Sum((IIf([Systems Access - Table]![NFC Form Date Submitted]Date()-61,1,0)))
Etc, etc.
So I have two quires that give me that data I need and they work. Now, I need to figure out a way to combine the quires by changing the fields that calculate NFC and eOPF separately and calculate them together.
I tried to build a summary request report but it wants to push the totals for eOPF over and I can’t line them up.
It looks like this:
Pending Date...0-30...31-60...61-90...90+...0-30...31-60...61-90...90+
NFC....................1.........4...........8........1
eOPF..............................................................2.........5.........1.........0
I’m getting frustrated and could really use some help.
Justin
I think what you are looking for is a "crosstab" query google a nit and you'll find many good examples for ms access.
This is one that helped me alot.
http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=25

I want to display clients based on a five day week on a form (All 5 days at once)

I've got a list of clients who have certain tasks done on a weekly basis. Currently we use an excel spreadsheet that keeps track of this but I am in the works of automating it. In the process of moving this into our MS Access system, I have created a form that does this for a single day and can display a report that outputs in the manner I want the form to look but I cannot get the form to look like that so the user can see all the days of the week for all the clients at once. I suppose I could do this in a subform per client but it seems a bit messy...
The spreadsheet we currently use has Column headers that state the Date and the rows are sort of grouped up by client that are for the number of times the given action occured, the timestamp of when it happened and other various data that happened on that day.
For the life of me I cannot think of a way to view all the records for that given week, grouped in detail per client all at once on the form. I can think of some ways to do this through VBA with recordsets but would like to know is there is a simpler way to do this that is easier to maintain.
Is there a way to do this with the use of a query and a few small scale tricks that don't involve storing recordsets? Keep in mind that this is for Access 2000, I only wish we would upgrade to '03.
Why not use five subforms? One for today, another for tomorrow, etc for
the next five business days. – Tony Toews Sep 12 at 20:57
That is the answer I've gone with and it works BEAUTIFULLY with the setup we are using. Thanks for the wonderful idea!