Skip to content

Commit

Permalink
Update entry selecting and graph frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
lr101 committed Aug 27, 2024
1 parent ac15bf0 commit 5638bf8
Show file tree
Hide file tree
Showing 29 changed files with 183 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ build/
### other ###
/bw-cloud/
/update.sh
/.env
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

14 changes: 4 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
ports:
- 8081:8081
env_file:
- ./.env
- .env
environment:
DB_HOST: db
EMAIL: lr.dev.projects@gmail.com
Expand All @@ -22,8 +22,8 @@ services:
# SECRET
depends_on:
- db
networks:
- net
- influxdb

db:
image: postgres:16
restart: unless-stopped
Expand All @@ -34,10 +34,4 @@ services:
- ./postgres-data:/var/lib/postgresql/data
- ./backup:/backup
env_file:
- ./.env
networks:
- net

networks:
net:
name: "stick-it-network"
- .env
1 change: 1 addition & 0 deletions openapi/methods/sensorsEntryById.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ get:
- $ref: '../parameters/date1.yaml'
- $ref: '../parameters/date2.yaml'
- $ref: '../parameters/limit.yaml'
- $ref: '../parameters/interval.yaml'
responses:
'200':
description: A list of sensor entries
Expand Down
19 changes: 0 additions & 19 deletions openapi/methods/sensorsGraph.yaml

This file was deleted.

8 changes: 3 additions & 5 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ info:
servers:
- url: 'http'
paths:
/rest/v1/categories/:
/rest/v1/categories:
$ref: './methods/categories.yaml'
/rest/v1/categories/{categoryId}:
$ref: './methods/categoriesById.yaml'
/rest/v1/sensors/{sensorId}:
$ref: './methods/sensorsEntryById.yaml'
$ref: './methods/sensorsById.yaml'
/rest/v1/sensors:
$ref: './methods/sensors.yaml'
/rest/v1/sensors/{sensorId}/entry:
$ref: './methods/sensorsById.yaml'
/rest/v1/sensors/{sensorId}/graph:
$ref: './methods/sensorsGraph.yaml'
$ref: './methods/sensorsEntryById.yaml'
/rest/v1/types:
$ref: './methods/sensorTypes.yaml'
/rest/v1/types/{typeId}:
Expand Down
4 changes: 2 additions & 2 deletions openapi/parameters/date1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ in: query
required: false
description: The start date (timestamp) for filtering entries
schema:
type: integer
format: int64
type: string
format: date-time
5 changes: 3 additions & 2 deletions openapi/parameters/date2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ in: query
required: false
description: The end date (timestamp) for filtering entries
schema:
type: integer
format: int64
type: string
format: date-time

2 changes: 1 addition & 1 deletion openapi/parameters/interval.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: interval
in: query
required: true
required: false
description: The interval for the graph data
schema:
type: integer
7 changes: 0 additions & 7 deletions openapi/schemas/entryDto.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
type: object
properties:
id:
type: integer
format: int64
description: The ID of the entry
sensorId:
type: string
description: The ID of the sensor
timestamp:
type: string
format: date-time
Expand Down
69 changes: 55 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,14 @@
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
Expand All @@ -135,28 +134,42 @@
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/kotlin</source>
<source>target/generated-test-sources/test-annotations</source>
<source>target/generated-sources/openapi/src/main/java</source>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<jvmTarget>${maven.compiler.target}</jvmTarget>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
<plugin>jpa</plugin>
</compilerPlugins>
<jvmTarget>${java.version}</jvmTarget>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.7.0</version>
<version>6.6.0</version>
<executions>
<execution>
<goals>
Expand All @@ -183,7 +196,35 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</build>

</project>
13 changes: 9 additions & 4 deletions src/main/ardoino/ESP8622_DS18B20_https/ESP8622_DS18B20_https.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void setup() {
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
ping();
ping(host.c_str());
/*
* Setup Thermometers
* Send Thermometer serial number to server to setup db
Expand Down Expand Up @@ -114,6 +114,12 @@ void setup() {
infos[i].sensor_id = sensor_id;
infos[i].values = new float[infos[i].repetitions];
infos[i].curValue = infos[i].values;
Serial.println("Repetitions: " );
Serial.println(infos[i].repetitions);
Serial.println("Average sleep Time: ");
Serial.println(avgSleepTime);
Serial.println("New value every (in seconds): ");
Serial.println((avgSleepTime * infos[i].repetitions + (infos[i].repetitions * numberOfDevices * 400)) / 1000); // 450ms is the average time to read a sensor value
}
http.end();
}
Expand Down Expand Up @@ -166,7 +172,7 @@ void loop() {
}
}
delay(avgSleepTime);
ping();
// ping(host.c_str());
}

float getAvg(float* p, int repetitions) {
Expand Down Expand Up @@ -227,8 +233,7 @@ String decToHexa(int n)
return hex;
}

void ping() {
const char* pinHost = "https://mona-sticker.herokuapp.com";
void ping(const char* pinHost) {

WiFiClientSecure client2; //WiFiClientSecure
client2.setInsecure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import de.lrprojects.tempserver.service.api.EntryService
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Component
import java.time.OffsetDateTime

@Component
class EntryDelegate(
private val entryService: EntryService
): SensorEntriesApiDelegate {

override fun deleteEntry(sensorId: String, date1: Long?, date2: Long?): ResponseEntity<Void> {
override fun deleteEntry(sensorId: String, date1: OffsetDateTime, date2: OffsetDateTime): ResponseEntity<Void> {
entryService.deleteEntries(sensorId, date1, date2)
return ResponseEntity.ok().build()
}

override fun getEntries(
sensorId: String,
date1: Long?,
date2: Long?,
limit: Int?
): ResponseEntity<MutableList<EntryDto>> {
return ResponseEntity.ok(entryService.getEntries(sensorId, date1, date2, limit).map { it.toDto() }.toMutableList())
date1: OffsetDateTime?,
date2: OffsetDateTime?,
limit: Int?,
interval: Int?
): ResponseEntity<MutableList<EntryDto>>? {
return ResponseEntity.ok(entryService.getEntries(sensorId, date1, date2, limit, interval).map { it.toDto() }.toMutableList())
}

override fun postEntry(sensorId: String, entryDto: EntryDto): ResponseEntity<Void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class ViewController(
}

@GetMapping(DISPLAY)
fun display(@RequestParam sensor_id: String, model: Model): String {
fun display(@RequestParam("sensor_id") sensorId: String, model: Model): String {
val sensors = sensorService.getAllSensors()
val sensor = sensorService.getSensorById(sensor_id)
val sensor = sensorService.getSensorById(sensorId)
model.addAttribute("sensors", sensors)
model.addAttribute("thisSensor", sensor)
return "display"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import java.time.OffsetDateTime
import java.time.ZoneOffset

fun Entry.toDto() = EntryDto().also {
it.sensorId = this.sensorId
it.value = this.value
it.timestamp = OffsetDateTime.of(this.timestamp!!.toLocalDateTime(), ZoneOffset.UTC)
}

fun EntryDto.toEntity() = Entry().also {
it.sensorId = this.sensorId
it.value = this.value
it.timestamp = Timestamp.from(this.timestamp.toInstant())
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fun Sensor.toDto() = SensorDto().also {
fun SensorDto.toEntity(typeService: TypeService) = Sensor().also {
it.id = this.sensorId
it.sensorNick = this.sensorNick
it.type = typeService.getTypeByName(this.sensorType)
it.type = this.sensorType?.let { type -> typeService.getTypeByName(type) }
}
1 change: 0 additions & 1 deletion src/main/kotlin/de/lrprojects/tempserver/entity/Entry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import java.sql.Timestamp
data class Entry(
var timestamp: Timestamp? = null,
var value: Double? = null,
var sensorId: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package de.lrprojects.tempserver.Schedular
package de.lrprojects.tempserver.schedular

import de.lrprojects.tempserver.service.api.EntryService
import de.lrprojects.tempserver.service.api.SensorService
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.sql.SQLException
import java.time.Instant
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util.*

@Component
@EnableScheduling
Expand All @@ -18,7 +22,7 @@ class DailyExecution(
@Throws(SQLException::class)
fun moveToBackup() {
val sensors = sensorService.getAllSensors()
val date = System.currentTimeMillis() - DAYS * 24 * 60 * 60 * 1000
val date = OffsetDateTime.ofInstant(Instant.now(), ZoneOffset.UTC)
for (sensor in sensors) {
entryService.deleteEntries(sensor.id!!, date, null)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package de.lrprojects.tempserver.service.api

import de.lrprojects.tempserver.entity.Entry
import java.time.OffsetDateTime

interface EntryService {

fun getEntries(sensorId: String, date1: Long?, date2: Long?, limit: Int?): List<Entry>
fun getEntries(sensorId: String, date1: OffsetDateTime?, date2: OffsetDateTime?, limit: Int?, interval: Int?): List<Entry>

fun createEntry(sensorId: String, entry: Entry)

fun deleteEntries(sensorId: String, date1: Long?, date2: Long?)
fun deleteEntries(sensorId: String, date1: OffsetDateTime?, date2: OffsetDateTime?)

}
Loading

0 comments on commit 5638bf8

Please sign in to comment.