Przeglądaj źródła

Log entries to console + increase max time + linear light

- Add a button (usually hidden) to log the raw entries to console to aid in debugging.
- Increase the max time to 8 weeks, as the data usage has been minimal thus far.
- Light made linear, instead of logarithmic, as I didn't like the way log looked.
Jason Tarka 1 rok temu
rodzic
commit
fdd0ffa6d8

+ 1 - 0
web-view/src/index.html

@@ -77,6 +77,7 @@
 			Hours to show:
 			<select id="hours-ago"></select>
 		</label>
+<!--		<button id="log-entries">Log raw entries</button>-->
 	</div>
 
 	<!--suppress HtmlUnknownTarget -->

+ 3 - 1
web-view/src/js/consts.ts

@@ -1,6 +1,6 @@
 export const HOURS_QUERY:string = 'hours';
 export const HOURS_DEFAULT:number = 12;
-export const MAX_HOURS_AGO = 672;
+export const MAX_HOURS_AGO:number = 1344; // 8 weeks
 
 /**
  * The total padding to add to a range on a graph to make tiny differences
@@ -142,4 +142,6 @@ export const HOUR_OPTIONS: Array<number|[number, string]> = [
 	[168, '1 week'],
 	[336, '2 weeks'],
 	[672, '4 weeks'],
+	[1008, '6 weeks'],
+	[1344, '8 weeks'],
 ];

+ 4 - 4
web-view/src/js/graphs.ts

@@ -103,10 +103,10 @@ function createGraph(
 		}
 	};
 
-	if(fieldInfo.key === 'light') {
-		const scale = config.options.scales.y;
-		scale.type = 'logarithmic';
-	}
+	// if(fieldInfo.key === 'light') {
+	// 	const scale = config.options.scales.y;
+	// 	scale.type = 'logarithmic';
+	// }
 
 	new Chart(canvas, config);
 }

+ 31 - 0
web-view/src/js/main.ts

@@ -42,6 +42,8 @@ async function init() {
 	);
 
 	showHourSelection();
+	document.getElementById('log-entries')
+		.addEventListener('click', () => logReadings(readings));
 }
 
 function getHoursAgo():number {
@@ -119,3 +121,32 @@ async function getRecentData(
 		});
 	});
 }
+
+/**
+ * Log readings to the console in a way that can be imported to a spreadsheet.
+ * @param readings The list of readings to log.
+ */
+function logReadings(readings: Reading[]) {
+	const separator = '\t';
+	const header = [
+		'Time',
+		'Temperature (C)',
+		'Humidity (%)',
+		'Pressure (hPa)',
+		'Light',
+		'Delay (minutes)',
+	].join(separator);
+
+	const lines = readings.map(r => {
+		const time = new Date(r.time);
+		return [
+			`"${time.toLocaleDateString()} ${time.toLocaleTimeString()}"`,
+			r.temperature,
+			r.humidity,
+			r.pressure,
+			r.light,
+			r.delay,
+		].join(separator);
+	});
+	console.log(header + '\n' + lines.join('\n'));
+}