From d23532d510cb906f70ee54db228d991559afd832 Mon Sep 17 00:00:00 2001 From: lynxzp Date: Tue, 4 Jan 2022 09:22:38 +0200 Subject: [PATCH] report finished --- collector/sources/pkg/reports/online.go | 7 +++++-- collector/sources/pkg/store/store.go | 14 ++++++++------ collector/sources/pkg/webui/browser.go | 9 +++++++-- collector/sources/pkg/webui/www/index.html | 3 +-- collector/sources/pkg/webui/www/reports.js | 19 ++++++++++--------- collector/sources/pkg/webui/www/update.js | 8 +++++++- 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/collector/sources/pkg/reports/online.go b/collector/sources/pkg/reports/online.go index 5de5205..b99cce1 100644 --- a/collector/sources/pkg/reports/online.go +++ b/collector/sources/pkg/reports/online.go @@ -37,7 +37,7 @@ func init() { } func processRecord(record store.DataRecord) (string, int) { - scaleStr := strconv.Itoa(record.Scale) + record.Fraction + scaleStr := strconv.Itoa(record.Scale) + "_" + record.Fraction if record.Event == "start" { prevRecordAccumulation[scaleStr] = record.Accumulation return "", 0 @@ -45,12 +45,15 @@ func processRecord(record store.DataRecord) (string, int) { if record.Event == "periodic" { prev, ok := prevRecordAccumulation[scaleStr] if !ok { + prevRecordAccumulation[scaleStr] = record.Accumulation log.Println("WW periodic save without start", record) return "", 0 } sum := record.Accumulation - prev if sum < 0 { - log.Println("WW the previous accumulation", prevRecordAccumulation[scaleStr], "is greater than the current one", record) + //todo: chek this + prevRecordAccumulation[scaleStr] = record.Accumulation + //log.Println("WW the previous accumulation", prevRecordAccumulation[scaleStr], "is greater than the current one", record) return "", 0 } return scaleStr, sum diff --git a/collector/sources/pkg/store/store.go b/collector/sources/pkg/store/store.go index f5eec47..0b4b9e4 100644 --- a/collector/sources/pkg/store/store.go +++ b/collector/sources/pkg/store/store.go @@ -37,7 +37,7 @@ func init() { log.Println("Database save closed") }) - sqlStmt := `CREATE TABLE if not exists scales (id INTEGER, ip TEXT, rs485addr INTEGER, data_perf_addr INTEGER)` + sqlStmt := `CREATE TABLE if not exists scales (id INTEGER, ip TEXT, rs485addr INTEGER, data_perf_addr INTEGER, fraction TEXT)` _, err = db.Exec(sqlStmt) if err != nil { log.Printf("EE %q: %s\n", err, sqlStmt) @@ -59,10 +59,10 @@ func init() { } } -func SaveScale(id int, dataPerfAddr int, ip string, rs485addr int) { +func SaveScale(id int, dataPerfAddr int, ip string, rs485addr int, fraction string) { ClearScale(id) - smt := "INSERT INTO scales (id, ip, rs485addr, data_perf_addr) VALUES(?, ?, ?, ?)" - res, err := db.Exec(smt, id, ip, rs485addr, dataPerfAddr) + smt := "INSERT INTO scales (id, ip, rs485addr, data_perf_addr, fraction) VALUES(?, ?, ?, ?, ?)" + res, err := db.Exec(smt, id, ip, rs485addr, dataPerfAddr, fraction) if err != nil { log.Println("WW can't save scales:", id, ip, rs485addr, dataPerfAddr, "with err:", err) return @@ -93,6 +93,7 @@ type Scale struct { DataPerfAddr int Ip string Rs485addr int + Fraction string } func ReadScales() ([]Scale, error) { @@ -104,15 +105,16 @@ func ReadScales() ([]Scale, error) { defer rows.Close() var id, rs485addr, dataPerfAddr int - var ip string + var ip, fraction string for rows.Next() { - err = rows.Scan(&id, &ip, &rs485addr, &dataPerfAddr) + err = rows.Scan(&id, &ip, &rs485addr, &dataPerfAddr, &fraction) if err != nil { continue } scales[id].Rs485addr = rs485addr scales[id].Ip = ip scales[id].DataPerfAddr = dataPerfAddr + scales[id].Fraction = fraction } return scales, nil } diff --git a/collector/sources/pkg/webui/browser.go b/collector/sources/pkg/webui/browser.go index ac3a62e..e71fe02 100644 --- a/collector/sources/pkg/webui/browser.go +++ b/collector/sources/pkg/webui/browser.go @@ -120,7 +120,12 @@ func ajaxSave(w http.ResponseWriter, r *http.Request) { return } - store.SaveScale(int(id), int(dataPerfAddr), ipaddr[0], int(rs485addr)) + fractionStr, ok := r.URL.Query()["fraction"] + if !ok || len(fractionStr[0]) < 1 { + return + } + + store.SaveScale(int(id), int(dataPerfAddr), ipaddr[0], int(rs485addr), fractionStr[0]) reloadScales() scales[id].Requests = 0 scales[id].Responses = 0 @@ -201,7 +206,6 @@ func reportH(w http.ResponseWriter, r *http.Request) { params[i].Accumulation = m } - log.Println(params) resp, err := json.Marshal(params) if err != nil { log.Println(err) @@ -265,5 +269,6 @@ func reloadScales() { scales[i].DataPerfAddr = uint16(s[i].DataPerfAddr) scales[i].Rs485addr = uint8(s[i].Rs485addr) scales[i].IP = s[i].Ip + scales[i].Fraction = s[i].Fraction } } diff --git a/collector/sources/pkg/webui/www/index.html b/collector/sources/pkg/webui/www/index.html index 85596cc..3b5b48d 100644 --- a/collector/sources/pkg/webui/www/index.html +++ b/collector/sources/pkg/webui/www/index.html @@ -48,9 +48,8 @@ ЛК-14 5*10------- ЛК-15 10*20------- ЛК-17 5*20------- - ЛК-4 песок(0*5)------- + ЛК-4 песок(0-5)------- -
diff --git a/collector/sources/pkg/webui/www/reports.js b/collector/sources/pkg/webui/www/reports.js index 4bbc42c..7cbfaba 100644 --- a/collector/sources/pkg/webui/www/reports.js +++ b/collector/sources/pkg/webui/www/reports.js @@ -1,19 +1,21 @@ function refreshReports() { + // if(document.getElementById("tseha").style.display !== "block") + // return let t = new Date() formatTime(t) let todayStart = t.setHours(0,0,0,0) let todayFinish = t.setHours( 23, 59, 59, 999) - let monthStart = new Date(t.setDate(1)) - let monthFinish = new Date(monthStart.getFullYear(), monthStart.getMonth() + 1, 0) - monthFinish = t.setDate(monthFinish.getDate()) - let yearstart = new Date(monthStart.setMonth(0)) - let yearfinish = new Date(monthStart.setMonth(11)) let params = []; params.push({start:formatTime(todayStart), end:formatTime(todayFinish), shift: 1, column: "todaycolshift1"}) params.push({start:formatTime(todayStart), end:formatTime(todayFinish), shift: 2, column: "todaycolshift2"}) params.push({start:formatTime(todayStart), end:formatTime(todayFinish), shift: 3, column: "todaycolshift3"}) params.push({start:formatTime(todayStart), end:formatTime(todayFinish), shift: 0, column: "todaycol"}) + let monthStart = new Date(t.setDate(1)) + let monthFinish = new Date(monthStart.getFullYear(), monthStart.getMonth() + 1, 0) + monthFinish = t.setDate(monthFinish.getDate()) params.push({start:formatTime(monthStart), end:formatTime(monthFinish), shift: 0, column: "monthcol"}) + let yearstart = new Date(monthStart.setMonth(0)) + let yearfinish = new Date(monthStart.setMonth(11)) params.push({start:formatTime(yearstart), end:formatTime(yearfinish), shift: 0, column: "yearcol"}) reportRequest(params) // todo: @@ -54,7 +56,7 @@ function reportRequest(struct) { httpReportRequest.send(); } -let scfr=['0', '00*40', '00*70', '020*40', '020*70', '15*10', '210*20', '25*20', '3песок(0*5)', '45*10', '510*20', '65*20', '7песок(0-5)'] +let scfr=[['0_песок(0-5)', 11], ['1_0*40', 0], ['1_0*70', 1], ['1_20*40', 2], ['1_20*70', 3] , ['2_5*10', 4], ['3_10*20', 5] ,['3_5*20', 6], ['4_песок(0-5)', 7], ['5_5*10', 8], ['6_10*20', 9], ['7_5*20', 10]] function reportResponse() { if (httpReportRequest.readyState === XMLHttpRequest.DONE) { @@ -63,12 +65,11 @@ function reportResponse() { let params = JSON.parse(httpReportRequest.responseText) for (let i=0; i<6; i++) { for (let j=0; j