patrickhener / growatt-display Goto Github PK
View Code? Open in Web Editor NEWYou can use the api to render a text display to see your stats
You can use the api to render a text display to see your stats
Last week now is 0 for me because last week is actually derived from the data of last month and this is totally wrong:
// Last Week (monday - sunday)
year, week := time.Now().ISOWeek()
week = week - 1
// Find Last Monday
start, _ := utils.DateRange(week, year)
mon := start.Day()
sun := mon + 6
// Last Month (all)
lastMonth := time.Now().AddDate(0, -1, 0)
lastMonthData, err := api.PlantDetail(id, string(utils.Month), lastMonth)
if err != nil {
return prevData, err
}
// Go over data map and fill both counters
lastWeekEnergy := 0.0
lastMonthEnergy := 0.0
for d, e := range lastMonthData.Back.Data {
dInt, err := strconv.Atoi(d)
if err != nil {
return prevData, err
}
eFloat, err := strconv.ParseFloat(e, 32)
if err != nil {
return prevData, err
}
// Conditonally calc to Week Energy
for i := mon; i <= sun; i++ {
if dInt == i {
lastWeekEnergy = lastWeekEnergy + eFloat
}
}
// Calc to total Energy
lastMonthEnergy = lastWeekEnergy + eFloat
}
Also this code does not take into account that a week from Monday to Sunday might leap over the change of a month. So if Monday is 28th of March so Sunday is 3rd of April. I need to take this into account as well.
In general lastWeek info has to be derived from current Month data. Then it has to be checked if lastWeek Sunday - 6 is less than 1 in the current month. If so it has to be calculated how much less and then last month data and this month data has to be combined accordingly to calculate the "real" last week.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.