Skip to content

Commit

Permalink
#219 Optimizations for Upload (2)
Browse files Browse the repository at this point in the history
Add option "only_upload_when_not_measuring"
  • Loading branch information
dostuffthatmatters committed May 16, 2024
1 parent 3fd3f14 commit 9c592fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/core/threads/upload_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ def should_be_running(config: types.Config) -> bool:
UploadThread.last_measurement_time = datetime.datetime.now()

# don't upload if system has been measuring in the last 10 minutes
if UploadThread.last_measurement_time is not None:
if ((datetime.datetime.now() -
UploadThread.last_measurement_time).total_seconds() < 600):
return False
if config.upload.only_upload_when_not_measuring:
if UploadThread.last_measurement_time is not None:
if ((datetime.datetime.now() -
UploadThread.last_measurement_time).total_seconds() < 600):
return False

return True

Expand Down
2 changes: 2 additions & 0 deletions packages/core/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class UploadConfig(StricterBaseModel):
user: str
password: str
only_upload_at_night: bool
only_upload_when_not_measuring: bool
streams: list[UploadStreamConfig]


Expand All @@ -252,6 +253,7 @@ class PartialUploadConfig(StricterBaseModel):
user: Optional[str] = None
password: Optional[str] = None
only_upload_at_night: Optional[bool] = None
only_upload_when_not_measuring: Optional[bool] = None
streams: Optional[list[UploadStreamConfig]] = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ export default function ConfigSectionUpload() {
setValue={(v: string) => setLocalConfigItem('upload.password', v)}
oldValue={centralSectionConfig !== null ? centralSectionConfig.password : 'null'}
/>
<configurationComponents.ConfigElementLine />
<configurationComponents.ConfigElementNote>
The upload only uploads data after the day of recording, so it works during active
measurements. However, you can use the following two options to reduce the load on
the PC during measurements.
</configurationComponents.ConfigElementNote>
<configurationComponents.ConfigElementBooleanToggle
title="Only Upload At Night"
value={localSectionConfig.only_upload_at_night}
Expand All @@ -149,6 +155,17 @@ export default function ConfigSectionUpload() {
<configurationComponents.ConfigElementNote>
At night = below 0° sun elevation
</configurationComponents.ConfigElementNote>
<configurationComponents.ConfigElementBooleanToggle
title="Only Upload When Not Measuring"
value={localSectionConfig.only_upload_when_not_measuring}
setValue={(v: boolean) => setLocalConfigItem(`upload.only_upload_when_not_measuring`, v)}
oldValue={
centralSectionConfig !== null ? centralSectionConfig.only_upload_when_not_measuring : null
}
/>
<configurationComponents.ConfigElementNote>
Stops upload immediately
</configurationComponents.ConfigElementNote>
<configurationComponents.ConfigElementLine />
{localSectionConfig.streams.map((stream, index) => (
<Fragment key={`${index}`}>
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/utils/zustand-utils/config-zustand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const configSchema = z.object({
user: z.string(),
password: z.string(),
only_upload_at_night: z.boolean(),
only_upload_when_not_measuring: z.boolean(),
streams: z.array(
z.object({
is_active: z.boolean(),
Expand Down

0 comments on commit 9c592fd

Please sign in to comment.