From bbb4680c0ab0460a52761518d61d8146e6857b27 Mon Sep 17 00:00:00 2001 From: ddnthemc Date: Tue, 8 Apr 2025 12:37:14 +0200 Subject: [PATCH] Aggiunti tempi di albe e tramonti con twilight zones --- .gitignore | 1 + .idea/.gitignore | 3 + .idea/OCR_Dome.iml | 8 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + README.md | 3 + all_measurements_saved.json | 1248 +++++++++++++++++ json_extensions.py | 39 + ocr01.py | 83 ++ plt_example.py | 39 + reload_data.py | 33 + show_data.py | 207 +++ test_twilight.py | 61 + 15 files changed, 1752 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/OCR_Dome.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 README.md create mode 100644 all_measurements_saved.json create mode 100644 json_extensions.py create mode 100644 ocr01.py create mode 100644 plt_example.py create mode 100644 reload_data.py create mode 100644 show_data.py create mode 100644 test_twilight.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a706e32 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/crps/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/OCR_Dome.iml b/.idea/OCR_Dome.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/OCR_Dome.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a6218fe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a8b8b61 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..070a9a3 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Con ocr01.py acquisisci i dati dagli screenshot (in modo cumulativo su all_measures.json) +Poi con reload_data.py ottieni la versione ripulita: clean_data.json +Poi con show_data crei i file di visualizzazione. diff --git a/all_measurements_saved.json b/all_measurements_saved.json new file mode 100644 index 0000000..97a03fb --- /dev/null +++ b/all_measurements_saved.json @@ -0,0 +1,1248 @@ +[ + { + "epoch": 1737448786.0, + "batt_full": "", + "name": "Security Camera\n", + "charging": false, + "perc": "91% |\n" + }, + { + "epoch": 1739225206.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1739252232.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1740770367.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "51% |\n" + }, + { + "epoch": 1740805445.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1740813237.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1740856873.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "46% |\n" + }, + { + "epoch": 1740859107.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "46% |\n" + }, + { + "epoch": 1740897222.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1741993093.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742017025.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742108392.0, + "batt_full": "The battery is full\n", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742108397.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742113371.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742192837.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742231839.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "92% |\n" + }, + { + "epoch": 1742232616.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "79% |\n" + }, + { + "epoch": 1742275259.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742276189.0, + "batt_full": "The battery is full\n", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742276194.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742281921.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742287470.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742292318.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742307279.0, + "batt_full": "", + "name": "Front door\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1742325421.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742326231.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742326322.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742329232.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742331244.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742338366.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742361669.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742369221.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742369710.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742373375.0, + "batt_full": "| Va\n", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742388794.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742426043.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742450538.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742490512.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1742492697.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "99% |\n" + }, + { + "epoch": 1742506204.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "99% |\n" + }, + { + "epoch": 1742511407.0, + "batt_full": ". \\- ain\n", + "name": "Front door\n", + "charging": false, + "perc": "99% |\n" + }, + { + "epoch": 1742533627.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1742534949.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1742552628.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1742556792.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1742561831.0, + "batt_full": "[Zz\n", + "name": "Front door\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1742596960.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1742625384.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "97% |\n" + }, + { + "epoch": 1742710801.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "96% |\n" + }, + { + "epoch": 1742714510.0, + "batt_full": "7 bi, ie\n", + "name": "Front door\n", + "charging": false, + "perc": "96% |\n" + }, + { + "epoch": 1742715087.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "96% |\n" + }, + { + "epoch": 1742741567.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "96% |\n" + }, + { + "epoch": 1742750783.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "96% |\n" + }, + { + "epoch": 1742774746.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "95% |\n" + }, + { + "epoch": 1742796941.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "95% |\n" + }, + { + "epoch": 1742804191.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "95% |\n" + }, + { + "epoch": 1742808898.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "95% |\n" + }, + { + "epoch": 1742833699.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "95% |\n" + }, + { + "epoch": 1742883875.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "94% |\n" + }, + { + "epoch": 1742968832.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "92% |\n" + }, + { + "epoch": 1743060738.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "90% |\n" + }, + { + "epoch": 1743071229.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "90% |\n" + }, + { + "epoch": 1743071729.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "90% |\n" + }, + { + "epoch": 1743080913.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "90% |\n" + }, + { + "epoch": 1743091046.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "89% |\n" + }, + { + "epoch": 1743140361.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "87% |\n" + }, + { + "epoch": 1743180886.0, + "batt_full": "", + "name": "Ext Front\n", + "charging": true, + "perc": "33% |\n" + }, + { + "epoch": 1743181469.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "88% |\n" + }, + { + "epoch": 1743200845.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "87% |\n" + }, + { + "epoch": 1743225434.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "86% |\n" + }, + { + "epoch": 1743239275.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "31% |\n" + }, + { + "epoch": 1743239385.0, + "batt_full": "|\n", + "name": "Front door\n", + "charging": false, + "perc": "86% |\n" + }, + { + "epoch": 1743239421.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "86% |\n" + }, + { + "epoch": 1743239460.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "31% |\n" + }, + { + "epoch": 1743242103.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "31% |\n" + }, + { + "epoch": 1743246527.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "86% |\n" + }, + { + "epoch": 1743246657.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "31% |\n" + }, + { + "epoch": 1743259073.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "36% |\n" + }, + { + "epoch": 1743260674.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "36% |\n" + }, + { + "epoch": 1743260684.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "85% |\n" + }, + { + "epoch": 1743274759.0, + "batt_full": ". \\ ie\n", + "name": "Front door\n", + "charging": false, + "perc": "85% |\n" + }, + { + "epoch": 1743274776.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "36% |\n" + }, + { + "epoch": 1743290606.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "36% |\n" + }, + { + "epoch": 1743290622.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743314805.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "35% |\n" + }, + { + "epoch": 1743314819.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743318161.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743318170.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "45% |\n" + }, + { + "epoch": 1743318956.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "48% |\n" + }, + { + "epoch": 1743318972.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743320566.0, + "batt_full": "me\n", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743320577.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "55% |\n" + }, + { + "epoch": 1743325873.0, + "batt_full": "nm\n\n", + "name": "Ext2\n", + "charging": true, + "perc": "77% |\n" + }, + { + "epoch": 1743325885.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743331859.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "96% |\n" + }, + { + "epoch": 1743331873.0, + "batt_full": "me\n", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743333650.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743333658.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743339446.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743339456.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743346347.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743346358.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743349186.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743349194.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743355636.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743355649.0, + "batt_full": "_\u2014\n\nSs\n", + "name": "Front door\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743365049.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "83% |\n" + }, + { + "epoch": 1743365058.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "60% |\n" + }, + { + "epoch": 1743365689.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "70% |\n" + }, + { + "epoch": 1743365724.0, + "batt_full": ".\\ ay\n", + "name": "Front door\n", + "charging": false, + "perc": "83% |\n" + }, + { + "epoch": 1743365787.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "71% |\n" + }, + { + "epoch": 1743365889.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "72% |\n" + }, + { + "epoch": 1743366810.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "81% |\n" + }, + { + "epoch": 1743366834.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "83% |\n" + }, + { + "epoch": 1743366890.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "82% |\n" + }, + { + "epoch": 1743367203.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "84% |\n" + }, + { + "epoch": 1743368529.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "93% |\n" + }, + { + "epoch": 1743368562.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "83% |\n" + }, + { + "epoch": 1743368772.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "94% |\n" + }, + { + "epoch": 1743369023.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "96% |\n" + }, + { + "epoch": 1743369617.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1743369869.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "98% |\n" + }, + { + "epoch": 1743370064.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "99% |\n" + }, + { + "epoch": 1743370362.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "99% |\n" + }, + { + "epoch": 1743370525.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "99% |\n" + }, + { + "epoch": 1743370972.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1743371245.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1743373545.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1743396764.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "99% |\n" + }, + { + "epoch": 1743397567.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "99% |\n" + }, + { + "epoch": 1743398040.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "99% |\n" + }, + { + "epoch": 1743398048.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "81% |\n" + }, + { + "epoch": 1743398679.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "99% |\n" + }, + { + "epoch": 1743400628.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "99% |\n" + }, + { + "epoch": 1743401716.0, + "batt_full": "The battery is full\n", + "name": "Ext2\n", + "charging": true, + "perc": "99% |\n" + }, + { + "epoch": 1743401721.0, + "batt_full": "wy\n", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743405671.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743405687.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "81% |\n" + }, + { + "epoch": 1743405827.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "81% |\n" + }, + { + "epoch": 1743405840.0, + "batt_full": "The battery is full\n", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743405843.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743409882.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "82% |\n" + }, + { + "epoch": 1743410014.0, + "batt_full": "The battery is full\n", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743410018.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743417333.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743417347.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "82% |\n" + }, + { + "epoch": 1743424427.0, + "batt_full": "The battery is full\n", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743424431.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743424443.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "83% |\n" + }, + { + "epoch": 1743436289.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743436302.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "82% |\n" + }, + { + "epoch": 1743436965.0, + "batt_full": ". eae\n", + "name": "Front door\n", + "charging": false, + "perc": "81% |\n" + }, + { + "epoch": 1743438232.0, + "batt_full": "The battery is full\n", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743438239.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743438276.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "81% |\n" + }, + { + "epoch": 1743444669.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "58% |\n" + }, + { + "epoch": 1743444688.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "81% |\n" + }, + { + "epoch": 1743444876.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "58% |\n" + }, + { + "epoch": 1743445713.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "58% |\n" + }, + { + "epoch": 1743445966.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "62% |\n" + }, + { + "epoch": 1743445997.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "80% |\n" + }, + { + "epoch": 1743446144.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "65% |\n" + }, + { + "epoch": 1743446447.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "69% |\n" + }, + { + "epoch": 1743448777.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "91% |\n" + }, + { + "epoch": 1743448793.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "80% |\n" + }, + { + "epoch": 1743450707.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1743458500.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1743458512.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "80% |\n" + }, + { + "epoch": 1743482808.0, + "batt_full": "", + "name": "Ext2\n", + "charging": false, + "perc": "100%\n" + }, + { + "epoch": 1743482832.0, + "batt_full": "L\u2014\u2014\n\n\u2014\n", + "name": "Front door\n", + "charging": false, + "perc": "80% |\n" + }, + { + "epoch": 1743485052.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "78% |\n" + }, + { + "epoch": 1743485066.0, + "batt_full": "The battery is full\n", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743485070.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743490053.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743490067.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "78% |\n" + }, + { + "epoch": 1743491433.0, + "batt_full": "The battery is full\n", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743491436.0, + "batt_full": "", + "name": "Ext2\n", + "charging": true, + "perc": "100%\n" + }, + { + "epoch": 1743491449.0, + "batt_full": "", + "name": "Front door\n", + "charging": false, + "perc": "79% |\n" + } +] \ No newline at end of file diff --git a/json_extensions.py b/json_extensions.py new file mode 100644 index 0000000..9dcddd8 --- /dev/null +++ b/json_extensions.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import json +from decimal import Decimal +# from task_row_x import TaskRow, SimpleTaskRow + + +def load_from_json_file(infile): + with open(infile, 'r') as fin: + obj = json.load(fin) + return obj + + +class SpecialEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, Decimal): + return str(obj) # Or you could return str(obj) depending on your needs + # if isinstance(obj, TaskRow) or isinstance(obj, SimpleTaskRow): + if hasattr(obj, 'get_dict') and callable(getattr(obj, 'get_dict')): + return obj.get_dict() + if isinstance(obj, set): + return [str(v) for v in obj] + return super().default(obj) + + +def save_to_json_file(out_name, obj): + with open(out_name, 'w', encoding='utf-8', newline='\n') as fout: + json.dump(obj, fout, indent=4, cls=SpecialEncoder) + + +def save_to_json_str(obj): + return json.dumps(obj, indent=4, cls=SpecialEncoder) + +def main(): + pass + + +if __name__ == '__main__': + main() diff --git a/ocr01.py b/ocr01.py new file mode 100644 index 0000000..15e37b0 --- /dev/null +++ b/ocr01.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import pytesseract +from PIL import Image +from pathlib import Path +from datetime import datetime +# import numpy as np +import colorsys +from json_extensions import save_to_json_file, load_from_json_file + +save_file = Path('all_measurements.json') + + +# FOLDER = Path('C:/Mc/Dome/Telecamere/ScreenShots') +# FOLDER = Path('C:/Mc/Dome/Telecamere/ScreenShots2') +FOLDER = Path('C:/Mc/Dome/Telecamere/ScreenShots3') + + +CROPS = { + 'batt_full': (351, 1109, 389, 101), + 'name': (175, 143, 750, 109), + # 'batt': (48, 320, 25, 50), + 'batt': (56, 345, 9, 2), + 'perc': (83, 314, 123, 60), +} + + +def available_screenshot(base_folder: Path): + for f in base_folder.iterdir(): + if f.is_file() and f.suffix == '.jpg' and f.stem.startswith('Screenshot') and f.stem.endswith('0a7d545a89c1640e78c89a2ce00d525b'): + yield f + + +def main(base_folder: Path, out_folder=Path('crps')): + # for sc in sorted(available_screenshot(base_folder), key=lambda x:x.stem): + found = False + n = 0 + if save_file.is_file(): + measures = load_from_json_file(save_file) + else: + measures = [] + for sc in available_screenshot(base_folder): + n += 1 + _, f_date, _ = sc.stem.split('_') + dt = datetime.strptime(f_date[:-3], '%Y-%m-%d-%H-%M-%S') + # obj = {'dt': dt} + obj = {'epoch': dt.timestamp()} + # if f_date != '2025-03-16-07-59-52-21': + # continue + # print(sc.stem) + src_img = Image.open(sc) + for k, crp in CROPS.items(): + x0, y0, w, h = crp + x1 = x0 + w + y1 = y0 + h + cropped = src_img.crop((x0, y0, x1, y1)) + if k == 'batt': + # new_name = f'{k}_{f_date}.png' + # cropped.save(out_folder / new_name) + tot, grey = 0, 0 + for p in cropped.getdata(): + tot += 1 + r, g, b = p + h, s, v = colorsys.rgb_to_hsv(r / 255, g / 255, b / 255) + if s < 0.1 and v > 0.1: + grey += 1 + v = grey / tot + # print(f'{v:.1f}') + obj['charging'] = v > 0.8 + # obj['charging'] = is_mostly_white(cropped) + if k != 'batt': + text = pytesseract.image_to_string(cropped) + obj[k] = text + if k == 'batt_full' and len(text) > 3: + found = True + print(f'{f_date}: {obj}') + measures.append(obj) + save_to_json_file('all_measurements.json', measures) + return + + +if __name__ == '__main__': + main(FOLDER) diff --git a/plt_example.py b/plt_example.py new file mode 100644 index 0000000..edd1256 --- /dev/null +++ b/plt_example.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import matplotlib.pyplot as plt +import matplotlib.dates as mdates +import datetime + + +def main(): + # Sample data + epoch_times = [1696000000, 1696086400, 1696172800, 1696259200] # Epoch seconds + y_values = [10, 20, 15, 25] # Some y-axis values + + # Convert epoch times to datetime objects + dates = [datetime.datetime.fromtimestamp(ts) for ts in epoch_times] + + # Create the plot + fig, ax = plt.subplots() + ax.plot(dates, y_values, marker='o', linestyle='-') + + # Format the x-axis as date + # ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d\n%H:%M:%S')) # Customize as needed + ax.xaxis.set_major_locator(mdates.AutoDateLocator()) # Automatically adjusts for readability + ax.xaxis.set_major_formatter( + mdates.ConciseDateFormatter(ax.xaxis.get_major_locator())) + + # Rotate date labels for better visibility + plt.xticks(rotation=45) + + # Labels and title + plt.xlabel("Date & Time") + plt.ylabel("Values") + plt.title("Epoch to Human Readable Time Plot") + + # Show the plot + plt.show() + + +if __name__ == '__main__': + main() diff --git a/reload_data.py b/reload_data.py new file mode 100644 index 0000000..145cbb1 --- /dev/null +++ b/reload_data.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +from json_extensions import load_from_json_file, save_to_json_file + + +def main(): + clean_data: dict[str, list] = {} + obj = load_from_json_file('all_measurements.json') + names = set() + for row in obj: + name = row.get('name', '').strip('\n') + perc_s = row.get('perc', '').strip('\n') + charging = row.get('charging') + epoch = row.get('epoch') + batt_full_s = row.get('batt_full', '').strip('\n') + batt_full = 'The battery is full' in batt_full_s + if '%' not in perc_s: + raise ValueError(f'Missing % in {row}') + prc = int(perc_s.split('%', maxsplit=1)[0]) + names.add(name) + if name not in clean_data: + clean_data[name] = [] + new_row = {'epoch': epoch, 'soc': prc, 'battery_full': batt_full, 'charging': charging} + print(name, new_row) + clean_data[name].append(new_row) + print(names) + for lst in clean_data.values(): + lst.sort(key=lambda x: x['epoch']) + save_to_json_file('clean_data.json', clean_data) + + +if __name__ == '__main__': + main() diff --git a/show_data.py b/show_data.py new file mode 100644 index 0000000..c0ca08f --- /dev/null +++ b/show_data.py @@ -0,0 +1,207 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import matplotlib.pyplot as plt +import matplotlib.dates as mdates +import matplotlib.patches as mpatches + +from astral import LocationInfo +from astral.sun import sun + +import datetime +from json_extensions import load_from_json_file + + +city = LocationInfo("Rome", "Italy", "Europe/Rome", 44.448066, 11.270639) + + +def main(data): + # Sample data + # epoch_times = [1696000000, 1696086400, 1696172800, 1696259200] # Epoch seconds + # y_values = [10, 20, 15, 25] # Some y-axis values + + # Create the plot + fig, ax = plt.subplots(tight_layout=False, figsize=(30, 10)) + earliest = None + latest = None + for name_raw, serie in data.items(): + if name_raw in ('Security Camera', 'Ext Front'): + continue + name = {'Front door': 'Sample #1 No PV panel', 'Ext2': 'Sample #2 with PV Panel', }.get(name_raw, name_raw) + dates = [datetime.datetime.fromtimestamp(row['epoch']) for row in serie] + soc_v = [row['soc'] for row in serie] + if name_raw == 'Front door': + dates = dates[3:] + soc_v = soc_v[3:] + mi = min(dates) + ma = max(dates) + if earliest is None: + earliest = mi + latest = ma + else: + earliest = min(earliest, mi) + latest = max(latest, ma) + + # charging = [row['charging'] for row in serie] + # batt_full = [row['battery_full'] for row in serie] + # + # sizes = [] + # for c1, c2 in zip(charging, batt_full): + # if c1 and c2: + # sizes.append(100) # Example: Both conditions true + # elif c1: + # sizes.append(200) # Example: Only condition 1 true + # elif c2: + # sizes.append(300) # Example: Only condition 2 true + # else: + # sizes.append(400) # Example: Both conditions false + # + + ax.plot(dates, soc_v, '-o', lw=3, label=name) + + # for x, y, color in zip(dates, soc_v, sizes): + + # ax.plot(dates, y_values, marker='o', linestyle='-') + + print(earliest, latest) + current_day = earliest + first_time = True + while current_day < latest: + # print(current_day) + # Get solar times + s = sun(city.observer, date=current_day, tzinfo=city.timezone) + dawn = s['dawn'] + sunrise = s['sunrise'] + sunset = s['sunset'] + dusk = s['dusk'] + if first_time: + ax.axvspan(dawn, sunrise, color='deepskyblue', alpha=0.3, label='Twilight (-6°)') + ax.axvspan(sunset, dusk, color='deepskyblue', alpha=0.3) + ax.axvline(sunrise, color='orange', linestyle='--', label='Sunrise') + ax.axvline(sunset, color='red', linestyle='--', label='Sunset') + first_time = False + else: + ax.axvspan(dawn, sunrise, color='deepskyblue', alpha=0.3) + ax.axvspan(sunset, dusk, color='deepskyblue', alpha=0.3) + ax.axvline(sunrise, color='orange', linestyle='--') + ax.axvline(sunset, color='red', linestyle='--') + + current_day += datetime.timedelta(days=1) + + # Format the x-axis as date + # ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d\n%H:%M:%S')) # Customize as needed + ax.xaxis.set_major_locator( + mdates.AutoDateLocator(minticks=30, maxticks=60)) # Automatically adjusts for readability + ax.xaxis.set_major_formatter(mdates.ConciseDateFormatter(ax.xaxis.get_major_locator())) + + x_tail = datetime.datetime(year=2025, month=4, day=7, hour=7, minute=20) + y_tail = 85 + x_head = datetime.datetime(year=2025, month=4, day=7, hour=6, minute=59) + y_head = 100 + dx = x_head - x_tail + dy = y_head - y_tail + + # Rotate date labels for better visibility + # plt.xticks(rotation=45) + + arrow = mpatches.FancyArrowPatch((x_tail, y_tail), (x_head, y_head), mutation_scale=50) + ax.add_patch(arrow) + + # Labels and title + ax.grid() + ax.legend(loc='lower right', framealpha=1.0) + plt.xlabel("Date & Time") + plt.ylabel("Reported State of Charge [%]") + plt.title('Camera battery behaviour') + + img_num = 1 + out_name = f'{img_num}_f11.png' + img_num += 1 + fig.savefig(out_name, dpi=150) + + st1 = datetime.datetime(year=2025, month=3, day=29) + end1 = datetime.datetime(year=2025, month=4, day=8, hour=12) + ax.set_xlim(st1, end1) + txt = f'Problems:\nSample#2: After FW upgrade the problem looks the same\nSample#1: Discharge is not monotonic.' + annt = ax.text(0.3, 0.1, txt, ha='left', fontsize=20, bbox={'facecolor': 'lightgray', 'alpha': 0.85, 'pad': 5}, + transform=ax.transAxes) + # annt.set_text(txt) + # print(txt) + out_name = f'{img_num}_overview.png' + # out_name_svg = f'{img_num}_overview.svg' + out_name_pdf = f'{img_num}_overview.pdf' + # fig.savefig(out_name_svg) + fig.savefig(out_name_pdf) + img_num += 1 + fig.savefig(out_name, dpi=200) + + # + # st1 = datetime.datetime(year=2025, month=3, day=1) + # end1 = datetime.datetime(year=2025, month=3, day=3) + # ax.set_xlim(st1, end1) + # txt = f'We noticed battery level anomaly' + # # print(txt) + # annt = ax.text(0.1, 0.2, txt, ha='left', fontsize=20, bbox={'facecolor': 'cyan', 'alpha': 0.7, 'pad': 5}, + # transform=ax.transAxes) + # print(annt, type(annt)) + # out_name = f'{img_num}_first_anomaly.png' + # img_num += 1 + # fig.savefig(out_name, dpi=150) + # # annt.remove() + # + # st1 = datetime.datetime(year=2025, month=3, day=17) + # end1 = datetime.datetime(year=2025, month=3, day=19) + # ax.set_xlim(st1, end1) + # txt = f'We noticed battery level anomaly Again!' + # annt.set_text(txt) + # # print(txt) + # out_name = f'{img_num}_second_anomaly.png' + # img_num += 1 + # fig.savefig(out_name, dpi=150) + # + # st1 = datetime.datetime(year=2025, month=3, day=19) + # end1 = datetime.datetime(year=2025, month=4, day=1) + # ax.set_xlim(st1, end1) + # txt = f'We unplugged the PV panel as asked by supplier' + # annt.set_text(txt) + # # print(txt) + # out_name = f'{img_num}_unplugged.png' + # img_num += 1 + # fig.savefig(out_name, dpi=150) + # + # st1 = datetime.datetime(year=2025, month=3, day=29) + # end1 = datetime.datetime(year=2025, month=4, day=1) + # ax.set_xlim(st1, end1) + # txt = f'We started testing a second sample' + # annt.set_text(txt) + # # print(txt) + # out_name = f'{img_num}_Sample2.png' + # img_num += 1 + # fig.savefig(out_name, dpi=150) + # + # st1 = datetime.datetime(year=2025, month=3, day=30, hour=17, minute=30) + # end1 = datetime.datetime(year=2025, month=3, day=31, hour=9, minute=30) + # ax.set_xlim(st1, end1) + # txt = f'There are Anomalies in the evening and in the morning' + # annt.set_text(txt) + # # print(txt) + # out_name = f'{img_num}_Sample2_detail1.png' + # img_num += 1 + # fig.savefig(out_name, dpi=150) + # + # st1 = datetime.datetime(year=2025, month=3, day=31, hour=15, minute=30) + # end1 = datetime.datetime(year=2025, month=4, day=1, hour=10) + # ax.set_xlim(st1, end1) + # txt = f'Second day Sample#2 still show anomaly\nSample#1 has increasing battery level (Impossible)' + # annt.set_text(txt) + # # print(txt) + # out_name = f'{img_num}_Sample2_detail2.png' + # img_num += 1 + # fig.savefig(out_name, dpi=150) + + # Show the plot + # plt.show() + + +if __name__ == '__main__': + cln_data = load_from_json_file('clean_data.json') + main(cln_data) diff --git a/test_twilight.py b/test_twilight.py new file mode 100644 index 0000000..b6af642 --- /dev/null +++ b/test_twilight.py @@ -0,0 +1,61 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import matplotlib.pyplot as plt +import numpy as np +import matplotlib.dates as mdates +from datetime import datetime, timedelta +from astral import LocationInfo +from astral.sun import sun + + +def main(): + # Set your location + city = LocationInfo("Rome", "Italy", "Europe/Rome", 44.448066, 11.270639) + + # Choose the date + # date = datetime(2023, 3, 29) + # dawn: 2023-03-29 06:32:45.166761+02:00 + # sunrise: 2023-03-29 07:02:31.106176+02:00 + # noon: 2023-03-29 13:19:52+02:00 + # sunset: 2023-03-29 19:37:45.931604+02:00 + # dusk: 2023-03-29 20:07:37.090448+02:00 + date = datetime(2023, 3, 29) + + # Get solar times + s = sun(city.observer, date=date, tzinfo=city.timezone) + for k, v in s.items(): + print(f'{k}: {v}') + dawn = s['dawn'] + sunrise = s['sunrise'] + sunset = s['sunset'] + dusk = s['dusk'] + + # Generate time series data for one day + times = [date + timedelta(minutes=15 * i) for i in range(96 * 1)] + values = np.sin(np.linspace(0, 4 * np.pi, len(times))) # Some mock data + + # Create the plot + fig, ax = plt.subplots(figsize=(10, 5)) + ax.plot(times, values, label="Sensor Data", color='tab:blue') + + # Plot twilight periods as vertical bands + ax.axvspan(dawn, sunrise, color='lightskyblue', alpha=0.3, label='Morning Twilight') + ax.axvspan(sunset, dusk, color='lightskyblue', alpha=0.3, label='Evening Twilight') + + # Mark sunrise and sunset + ax.axvline(sunrise, color='orange', linestyle='--', label='Sunrise') + ax.axvline(sunset, color='red', linestyle='--', label='Sunset') + + # Formatting + ax.set_title(f"Daylight and Twilight - {city.name} on {date.strftime('%Y-%m-%d')}") + ax.set_xlabel("Time") + ax.set_ylabel("Sensor Value") + ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M')) + plt.xticks(rotation=45) + plt.legend() + plt.tight_layout() + plt.show() + + +if __name__ == '__main__': + main()