Skip to content

Commit

Permalink
yep
Browse files Browse the repository at this point in the history
  • Loading branch information
gtaharaedmonds committed Jun 6, 2024
1 parent 969c249 commit fc5ebec
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 38 deletions.
20 changes: 5 additions & 15 deletions software/tracksight/backend/app/flask_apps/http_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Tuple, Dict, List
from datetime import datetime, timedelta
import logging
from datetime import datetime

from influx_handler import InfluxHandler

Expand Down Expand Up @@ -62,15 +63,15 @@ def health() -> Tuple[Dict, int]:
return {"status": "healthy"}, 200


@app.route("/data/measurements", methods=["GET"])
@app.route("/measurements", methods=["GET"])
def return_all_measurements() -> Tuple[List[str], int]:
"""
:returns Page displaying all measurements in the database.
"""
return InfluxHandler.get_measurements(), 200


@app.route("/data/measurement/<string:measurement>/signals", methods=["GET"])
@app.route("/signals/<string:measurement>", methods=["GET"])
def return_signals_for_measurement(measurement: str) -> Tuple[List[str], int]:
"""
:param measurement: Measurement to fetch fields for.
Expand All @@ -79,16 +80,7 @@ def return_signals_for_measurement(measurement: str) -> Tuple[List[str], int]:
return InfluxHandler.get_signals(measurement=measurement), 200


@app.route("/data/measurement/wtf", methods=["GET"])
def return_live_signals() -> Tuple[List[str], int]:
"""
:param measurement: Measurement to fetch fields for.
:returns Page displaying all fields for a specific measurement.
"""
return InfluxHandler.get_signals(measurement="live"), 200


@app.route("/data/query/live", methods=["GET"])
@app.route("/query/live", methods=["GET"])
def return_live_query() -> Dict[str, Dict]:
"""
:returns Page displaying the result of a single query.
Expand All @@ -103,8 +95,6 @@ def return_live_query() -> Dict[str, Dict]:
start_epoch = int(start_time.timestamp())
end_epoch = int(end_time.timestamp())

logger.info(f"Start request: {start_epoch}, {end_epoch}")

return submit_query(
measurement=measurement,
signals=signals,
Expand All @@ -113,7 +103,7 @@ def return_live_query() -> Dict[str, Dict]:
)


@app.route("/data/query", methods=["GET"])
@app.route("/query", methods=["GET"])
def return_query() -> Dict[str, Dict]:
"""
:returns Page displaying the result of a single query.
Expand Down
2 changes: 1 addition & 1 deletion software/tracksight/backend/app/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
file = file.strip()
logger.info(f"Uploading data file: {file}")

path = os.path.join("data", file)
path = os.path.join(app_dir, "..", "data", file)
df = pd.read_csv(path)
InfluxHandler.write(df=df, measurement=file)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, Dispatch, SetStateAction } from 'react';
import { useState, useEffect, Dispatch, SetStateAction } from 'react';
import { Select } from 'antd';
import React from 'react';

Expand All @@ -11,7 +11,7 @@ export interface DropdownMenuProps {
}

const DropdownMenu = (props: DropdownMenuProps) => {
const [items, setItems] = useState<Array<{value: string, label: string}>>([]);
const [items, setItems] = useState<Array<{ value: string, label: string }>>([]);

useEffect(() => {
const updatedItems = props.options.map((name, index) => ({
Expand All @@ -20,13 +20,13 @@ const DropdownMenu = (props: DropdownMenuProps) => {
}));
setItems(updatedItems);
}, [props.options, props.selectedOptions]);

const handleChange = (value: string[]) => {
props.setOption(value);
};

const filterOption = (input: string, option?: { label: string; value: string }) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase());
(option?.label ?? '').toLowerCase().includes(input.toLowerCase());

return (
<Select
Expand All @@ -35,7 +35,7 @@ const DropdownMenu = (props: DropdownMenuProps) => {
placeholder={props.name}
filterOption={filterOption}
onChange={handleChange}
style={{width: "100%"}}
style={{ width: "100%" }}
options={items}
maxTagCount="responsive"
/>
Expand Down
6 changes: 3 additions & 3 deletions software/tracksight/frontend/src/app/components/db/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface GraphProps {
}

const Graph = (props: GraphProps) => {
const [data, setData] = useState<{ [name: string]: { time: Array<string>, value: Array<number> } }>({});
const [data, setData] = useState<{ [name: string]: { times: Array<string>, values: Array<number> } }>({});
const [formattedData, setFormattedData] = useState<Plotly.Data[]>([]);

//default graph layout
Expand Down Expand Up @@ -59,8 +59,8 @@ const Graph = (props: GraphProps) => {
const tempFormattedData: Plotly.Data[] = [];
for (const name in data) {
let signalData = data[name];
let xData = signalData["time"];
let yData = signalData["value"];
let xData = signalData["times"];
let yData = signalData["values"];

const formattedObj: Plotly.Data = {
x: xData,
Expand Down
28 changes: 14 additions & 14 deletions software/tracksight/frontend/src/app/components/db/query_data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import { MessageInstance } from 'antd/es/message/interface';

export interface QueryDataProps {
url: string,
setData: Dispatch<{ [name: string]: { time: Array<string>, value: Array<number> } }>,
setData: Dispatch<{ [name: string]: { times: Array<string>, values: Array<number> } }>,
messageApi: MessageInstance,
}

const QueryData = (props: QueryDataProps) => {
const [measurement, setMeasurement] = useState<string[]>([]);
const [allMeasurements, setAllMeasurements] = useState<string[]>([]);

const [fields, setFields] = useState<string[]>([]);
const [allFields, setAllFields] = useState<string[]>([]);
const [signals, setSignals] = useState<string[]>([]);
const [allSignal, setAllSignal] = useState<string[]>([]);

const [startEpoch, setStartEpoch] = useState<number | null>(null);
const [endEpoch, setEndEpoch] = useState<number | null>(null);

useEffect(() => {
fetch(props.url + "/signal/measurement", {
fetch(props.url + "/measurements", {
method: 'get',
}).then((response) => response.json())
.then((data) => setAllMeasurements(data))
Expand All @@ -36,22 +36,22 @@ const QueryData = (props: QueryDataProps) => {
}

const measurement_name = measurement[0];
fetch(props.url + "/signal/fields/" + measurement_name, {
fetch(props.url + "/signals/" + measurement_name, {
method: 'get',
}).then((response) => response.json())
.then((data) => setAllFields(data))
.then((data) => setAllSignal(data))
.catch((error) => console.log(error));
}, [measurement]);

const handleSubmit = () => {
if (!startEpoch || !endEpoch || !measurement || !fields.length) {
props.messageApi.open({ type: "error", content: "Please fill out all fields properly" });
if (!startEpoch || !endEpoch || !measurement || !signals.length) {
props.messageApi.open({ type: "error", content: "Please fill out all signal properly" });
return;
}
const newParams = new URLSearchParams({ measurement: measurement[0], start_epoch: startEpoch.toString(), end_epoch: endEpoch.toString() });
for (const field in fields) {
newParams.append('fields', fields[field]);
}
const newParams = new URLSearchParams({
measurement: measurement[0], start_epoch: startEpoch.toString(), end_epoch: endEpoch.toString(),
signals: signals.join(","),
});
fetch(props.url + "/query?" + newParams)
.then((response) => {
if (!response.ok) {
Expand All @@ -68,9 +68,9 @@ const QueryData = (props: QueryDataProps) => {
return (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<DropdownMenu setOption={setMeasurement} selectedOptions={measurement} options={allMeasurements} single={true} name={"Measurements"} />
<DropdownMenu setOption={setFields} selectedOptions={fields} options={allFields} single={false} name={"Fields"} />
<DropdownMenu setOption={setSignals} selectedOptions={signals} options={allSignal} single={false} name={"Signal"} />
<TimeStampPicker setStart={setStartEpoch} setEnd={setEndEpoch} />
<Button onClick={handleSubmit}>submit</Button>
<Button onClick={handleSubmit}>Submit</Button>
</div>);
}

Expand Down

0 comments on commit fc5ebec

Please sign in to comment.