I'm trying to get a Flux query that shows me what an average day looks like, over a given period. More specifically, I'm querying power usage data of my freezer, gathered and sent to InfluxDB by home assistant.
As a very basic example, if my freezer would have used 100W during the first 15 days of a 30 day period, and 0W during the last 15 days, the daily average of that 30 day period would be 50W.
What I want to see is a graph of a 24h time period, but with the average data of month.
I have this basic query which shows me a months worth of data:
from(bucket: "home_assistant/autogen")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["friendly_name"] == "Shelly plug S Freezer Power 0")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
|> yield(name: "mean")
By playing with the aggregateWindow function, changing the every parameter to 1d will show me the average data per day over those 30 days, but that's not what I want.
If you want to have 30 days average you can take a look at the timeMovingAverage. It will return an average of the current value and all row values in the previous period (duration). It returns moving averages at a frequency defined by every parameter.
Related
I have the data of 4000 employees in google sheets along with their shift timings (9 hour long shift) spread across 24 hours. I wish to use a formula to understand the most common timing these employees are available in the office (09:00 to 18:00). My results would be 09:00 to 11:00, 11:00 to 13:00, 13:00 to 15:00, 15:00 to 18:00, 18:00 to 22:00, 22:00 to 09:00.
I could have used this formula to derive to the value:
=IF(AND(TIMEVALUE(A2)>=TIMEVALUE("09:00"), TIMEVALUE(A2)<=TIMEVALUE("11:00")), "09:00 to 11:00",
IF(AND(TIMEVALUE(A2)>=TIMEVALUE("11:00"), TIMEVALUE(A2)<=TIMEVALUE("13:00")), "11:00 to 13:00",
IF(AND(TIMEVALUE(A2)>=TIMEVALUE("13:00"), TIMEVALUE(A2)<=TIMEVALUE("15:00")), "13:00 to 15:00",
IF(AND(TIMEVALUE(A2)>=TIMEVALUE("15:00"), TIMEVALUE(A2)<=TIMEVALUE("18:00")), "15:00 to 18:00",
IF(AND(TIMEVALUE(A2)>=TIMEVALUE("18:00"), TIMEVALUE(A2)<=TIMEVALUE("22:00")), "18:00 to 22:00", "22:00 to 09:00")))))
but the problem is the timings are not in the time format but they are in text format
Here's my take:
Suppose Column A has clock ins, and Column B has clock outs. Let Column D have Times starting at 00:00 and going up to 33:00 (8am next day) in 5 minute (or 30, 60 etc) increments.
Let column E be the amount of clock in and outs that an employee was in the office at the time referred to in E.
We will define E to be =COUNTIFS($A$2:$A$9999,"<="&D2,$B$2:$B$9999,">="&D2).
Next, apply some conditional formatting to highlight the most busy times.
Note that you will need only the times of day, which it sounds like you have, but you will need to convert overnight shifts to not wrap around midnight.
I have a few sensors that every 1st day of the month they reset the value. I have been using the last value with success but didnt find a way to get the max/last value in a given calendar month. For each calendar month, for each sensor I mean. I am a beginner working with flux.
I tried the agreggate with 1 month, but looks like it is not going to the last day of each month, and I wanted to have for each month.
I have several sensors that are cumulative per month, but on the first measurement of the month they go to zero. I wanted to have a way to visualise for each past month what the measurement was last, for all the sensors so I can put in grafana and see each month how it was the consumption.
This is my query, which returns the last value for each of the 20 sensors:
from(bucket: "home")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["friendly_name"] =~ /1MON$/ and r["friendly_name"] !~ /^Main/)
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["_measurement"] == "kWh")
|> filter(fn: (r) => r["entity_id"] !~ /2$/)
I have a tricky problem in Sheets.
I need a formula to calculate running total costs for each month from Nov 2019 on wards (column B).
Currently, my formula for B2 is:
=SUMIFS($F$2:$F$6,$E$2:$E$6,">="&A2,$E$2:$E$6,"<="&(EDATE(A2,1)-1))
Basically, this finds all values in cells F2:F6 whose dates (in column E) match that of A2.
E.g. Cell B3 is the total cost for December, so cells F3 and F6 are a match (200 + 300 = 500)
However, this does not take into account the duration of the cost (column G).
This means that the total cost for December 2019 (cell B3) should actually be 600 (because the November cost duration lasts 12 months). Meaning there is a cumulative cost for the duration of months the cost lasts for.
I am pretty much stuck on this. If anyone could help that would be great!
So as long as the date given in column A intersect between "start date" and "start date" + x months the cost per month should be applied?
So according to this, Jan-2020 will have a cost of 600 in this example:
Sant/Falskt = True/False
Green rows = date intersect between Start and End date
If that is correct then this formula should do the job, paste in B2:
=SUMPRODUCT((--(A2>=DATE(YEAR($E$2:$E$6),MONTH($E$2:$E$6),1))*--(A2<DATE(YEAR($E$2:$E$6),MONTH($E$2:$E$6)+$G$2:$G$6,DAY($E$2:$E$6))))*$F$2:$F$6)
I have a list of time slots with a 15 minute interval.
Each slot can have a activity bound to it that makes the slot "reserved".
What is the best way to return the slots in groups of 30 minutes.
So basically, how can I go from this:
10:00
10:15 = this is a reserved slot
10:30
To this:
10:00
10:30
This whole slot is then reserved because it contains the reserved 10:15 slot.
Without changing the slot size itself.
Is this possible to do within the linq query itself or do I have to return the collection of 15 minute slots and apply the 30 minute logic afterwards?
Please point me in the right direction, thanks!
The slots are object with these properties and types:
TimeslotId (int)
SlotStart (DateTime)
ActivityId (int)
UPDATE:
Ok, I tried to group the slots with this query.
var groups = service.TestGrouping().GroupBy(x =>
{
var stamp = x.SlotStart;
stamp = stamp.AddMinutes(-(stamp.Minute % 30));
stamp = stamp.AddMilliseconds(-stamp.Millisecond - 1000 * stamp.Second);
return stamp;
}).Select(g => new Sample() { GroupTime = g.Key, GroupedSlots = g.ToList() }).ToList();
Which takes me a little closer. Now I get the slots aggregated to closest 30 minute, like 8:00-8:30, 8:30-9:00.
However, this does not work for slots that is within quarter to / quarter past. I need some logic to catch all possible half hours:
8:00-8:30, 8:15-8:45, 8:30-9:00, 8:45-9:15.
How would the logic look like?
I am working on a call center software in rails and need to schedule appointments for agents that can handle calls for the customers. Having said the call center software, need to make sure that I schedule the appointments utilizing the entire agent's schedule as much as possible, leaving scope for least number of holes (where agent has no appointment).
Given an agent's schedule, for example 9:00AM to 5:30PM for a given day, with a lunch break of 30 minutes between 1:00PM - 1:30PM, I need to schedule appointments of varying length in duration, some 60 minutes and some 90 minutes.
And if some reason, lunch break is leaving some holes in the schedule, I should be able to move lunch break 30minutes +/-, so instead of 1:00PM - 1:30PM it could be moved between 1:30PM - 2:00PM or 12:30PM - 1:00PM.
I started off creating lunch breaks as a kind of appointment which will provide the flexibility of moving the starts_at and finishes_at attributes. And the appointments being either 60 minutes or 90 minutes, which are multiple of 30 minutes and lunch also being 30 minutes, I started off splitting agents schedule into slots of 30 minutes each.
So for a given agent on a given day, looking at his schedule I instantiated an array of slots each with a duration of 30 minutes and starts_at and finishes_at attributes be like 9:00AM - 9:30AM, 9:30AM - 10:00AM, etc.
I need some help on looping through this array of appointment slots and pull either 2 consecutive slots or 3 consecutive slots depending upon 60 or 90 minute duration appointment, keeping in mind that I should be able to move the lunch +/- 30 minutes.
Any help is much appreciated.
Looking at your problem:
Appointments are either 60 or 90 minutes long.
Lunch can vary between a 90 minute interval 12:30-2:00
And we want to minimize the amount of minutes that have no appointments.
Now, you have a time interval to fill, which is 9:00AM to 5:30pm. Assuming appointments fall between 9:00-5:30, we can use a greedy algorithm for interval scheduling based on earliest finish time (source) with your additional constraint.
Basically the algorithm is as follows (in pseudo)
Let R be the set of all appointments
Let R11 be the set of appointments from R before 12:30 that are compatible with 12:30-1:00 and R12 be the set of appointments from R after 1:00 that are compatible with 12:30-1:00
Let R21 be the set of appointments from R before 1:00 that are compatible with 1:00-1:30 and R22 be the set of appointments from R after 1:30 that are compatible with 1:00-1:30
Let R31 be the set of appointments from R before 1:30 that are compatible with 1:30-2:00 and R32 be the set of appointments from R after 2:00 that are compatible with 1:30-2:00
Let R1Comb = findSet(R11) + 12:30-1:00 + findSet(R12)
Let R2Comb = findSet(R21) + 1:00-1:30 + findSet(R22)
Let R3Comb = findSet(R31) + 1:30-2:00 + findSet(R32)
Function findSet(R)
Let A be the time interval to fill
While R is not empty
Choose a request r in R that has the smallest finishes_at
Add r to A
Remove all appointments in R that are not compatible with r
EndWhile
Return A
EndFunction
Return the R that has the smallest amount of holes in R1Comb, R2Comb, R3Comb
This algorithm makes use of a few concepts
An appointment r1 is not compatible with r2 if they overlap.
Because of #1, we know that Ri1/Ri2 for i=1,2,3 will not be conflicting with each other. Because if an appointment in Ri2 is not compatible with Ri1, then it is also not compatible with the lunch period, which is a contradiction because we took out all the non compatible appointments.
Once we split the set of appointments, then it's a matter of solving 2 scheduling problems, which can be solved greedily.
An this algorithm is still O(n log n) because you are doing the greedy algorithm 6 times (a constant), and each greedy iteration is O(n log n), and the first few lines and the last line are all O(n).
People write theses on scheduling and it's not an easy problem. I suggest you looking at http://www.asap.cs.nott.ac.uk/watt/resources/university.html to get a better understanding.
Good luck :)