Documentation of useTemperature and mock sensor. #249
Labels
No labels
_CRITICAL_
API
app
backEnd
Blocked, waiting for further changes
bug
cleanup
close
design
duplicate
enhancement
feature request
frontEnd
help wanted
invalid
low priority
needs input
needs review
project documentation
question
research
reviewed
script
security
SQL
style
testing
topLevel
wontfix
No milestone
No project
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Andras/BoundlessFlowCampus2K#249
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
API for Temprature
There exist two hooks one for latest datapoint and one for all datapoints.
Both gets called in App.Js with an parameter attached {sensorId} to choose witch sensor to get data from.
Example:
Latest Value:
<TemperatureView sensorId={'temp-sensor-004'}/>All Values:
<TemperatureTimeSeriesView sensorId={'temp-sensor-001'}/>Data returned from hook
Returns an JSON objekt containing data for sensorId,timestamp and temperature.
{"sensorId":"sensorId","timestamp":"timestamp","temperature":"temperature"}Returns an array of JSON objekts
[{"sensorId":"sensorId","timestamp":"timestamp","temperature":"temperature"}{"sensorId":"sensorId","timestamp":"timestamp","temperature":"temperature"}{"sensorId":"sensorId","timestamp":"timestamp","temperature":"temperature"}]View
To impliment a view the hook needs to be importad and called with the parmeter.
Example:
import { useTemperatureTimeSeriesView } from "./useTemperatureTimeSeriesView";export default function TemperatureTimeSeriesView({sensorId}) {const { data, loading, error } = useTemperatureTimeSeriesView(sensorId);import { useTemperature } from "./useTemperatureTimeSeriesView";export default function TemperatureView({sensorId}) {const { data, loading, error } = useTemperature(sensorId);Adding values to layout examples
When creating the layout the values gets accesed through data.collumnName when using useTemperature.js(Latest value)
Example:
<Card title="Temperatur"><p style={{ fontSize: '2rem', fontWeight: 'bold', margin: 0 }}>{data.temperature} °CSensor: {data.sensorId}</p>As data is an array of objects when useTemperatureTimeSeriesView.js(All values) is used the list need to be acceses before useing the JSON objects within.
implimentation depends on what the view will do but an Example is using.
const timeSeries = data.map((item, index)=>and call the values with item.ColumnName
return (<p key={index} style={{ color: '#5d9e57', fontSize: '1rem', marginTop: '0.5rem' }}>{time.toLocaleDateString("sv-SE", options)}: {item.temperature} °C ID:{item.sensorId}</p>)Adding more sensors
If more Sensors or diffrent sensorId names is needed/wanted you can add it in \tempSensorMockup by adding a new sensor with a name to the array.
var data = new[]
{new{sensorId = "temp-sensor-001",timestamp = DateTime.UtcNow,temperature = Math.Round(rand.NextDouble() * 15 + 10, 2)},new{sensorId = "temp-sensor-002",timestamp = DateTime.UtcNow,temperature = Math.Round(rand.NextDouble() * 15 + 10, 2)}};The decision and why
The intention was to create a mockupdata for temperature sensors where its easy to add more sensors to fit the need.
The API is supose to be able to return data for the latest datapoint of a specific sensor as well as an array with historic values.
Right now the historic data returnes everything in the database, when a view is created/desided on the array will need to be sliced and or filtered to get specific time intervalls and a max amount of objects.
Waiting for review before adding it to the wiki
Documentation
As of now the documentation do not refer to any code/branch/subissue which makes it much harder to review when I can not inspect the actual process.
Suggestion:
Make sure to refer to the implementation.
Wiki formating
Under "Adding more sensors" you have also missed to include
var data = new[]in the coding block, use proper formating when using code-format in the Wiki. You can press the three dots on my message, choose edit-message and see how the format is suppose to look like.Overall the documentation is well structure that clearly separates latest values from historical time series data. With the uses of mock sensors the approach is easy to understand and test and it is written in a way that makes it easy to extend and maintain.
However there are some issues that need to be addressed.
Firstly there are multiple spelling and naming inconsistencies/mistakes which results in reduced clarity and they should probably be corrected for consistency (examples: useTeperature, objekts)
Secondly, in the "useTemperature To get latest" example there are some inconsistencies that leads to confusion (e.g. importing useTemperature from a file named useTemperatureTimeSeriesView). useTemperatureTimeSeriesView appears to be intended for retrieving all the data.
Lastly the JSON examples would benefit from using realistic data format.
Instead of this:
{"sensorId":"sensorId","timestamp":"timestamp","temperature":"temperature"}
it should be this:
{
"sensorId": "temp-sensor-001",
"timestamp": "2026-04-13T10:15:00Z",
"temperature": 21.7
}
This simple change will increase the readability and makes the API contract clearer and more representative of the actual usage.
Great feedback, will fix the problems
API for Temperature
There are two hooks one for latest datapoint and one for all datapoints.
Both gets called in App.Js with a parameter attached {sensorId} to choose witch sensor to get data from.
Example:
Latest Value:
<TemperatureView sensorId={'temp-sensor-004'}/>All Values:
<TemperatureTimeSeriesView sensorId={'temp-sensor-001'}/>Data returned from hook
Returns an JSON object containing data for sensorId, timestamp and temperature.
Returns an array of JSON objects
View
To implement a view the hook needs to be imported and called with the parameter.
Example:
Adding values to layout examples
When creating the layout, the values get accessed through data.collumnName when using useTemperature.js(Latest value)
Example:
As data is an array of objects when useTemperatureTimeSeriesView.js(All values) is used the list needs to be accessed before using the JSON objects within.
implementation depends on what the view will do but an Example is using.
const timeSeries = data.map((item, index)=>and call the values with item.ColumnName
Adding more sensors
If more Sensors or different sensorId names are needed/wanted, you can add it in \tempSensorMockup by adding a new sensor with a name to the array.
The decision and why
The intention was to create a mockup data for temperature sensors where it’s easy to add more sensors to fit the need.
The API is supposed to be able to return data for the latest datapoint of a specific sensor as well as an array with historic values.
Right now, the historic data returns everything in the database, when a view is created/decided on the array will need to be sliced and or filtered to get specific time intervals and a max amount of objects.
This documentation is of Branch issue#7-multipleTemperatureMockSensors, issue: #7 & #12 , Its also merged to team_2_week_1
Changes
Overall, the documentation is well structured and clearly separates the latest values. It also gives a clear overview of how the temperature hook and mock sensor setup work. I believe that it is now suitable to be included in the wiki, So it can provide some guidelines before implementation.
One small suggestion is to make sure you use headers instead of just bold text to improve the readability and structure.
Added to wiki
@c24danli wrote in #249 (comment):
Good, then this issue can be closed.
Review has been done in a proper way. Good job!
Documentation av useTemperature och mock sensor.to Documentation of useTemperature and mock sensor.