added calculation for battery level with mock data and adjusted the types

This commit is contained in:
Mikail Killi 2024-10-13 22:39:54 +02:00
parent ff2d6c82c9
commit 644dd6394e
3 changed files with 57 additions and 25 deletions

View file

@ -27,11 +27,11 @@
</div>
<div class="d-flex align-items-center mb-2">
<span class="mr-2">Battery:</span>
<span>{{ node.battery }}%</span>
<span>{{ node.batteryCurrent }}%</span>
</div>
<div class="d-flex align-items-center mb-2">
<span class="mr-2">Runtime:</span>
<span>{{ node.runtime }} hours</span>
<span>{{ node.uptime }} hours</span>
</div>
</v-expansion-panel-text>
</v-expansion-panel>

View file

@ -5,8 +5,8 @@
<tr>
<th>Node/Name</th>
<th>Status</th>
<th>Latitude</th> <!-- Separate column for Latitude -->
<th>Longitude</th> <!-- Separate column for Longitude -->
<th>Latitude</th>
<th>Longitude</th>
<th>Battery</th>
<th>Gemessene - Temperatur</th>
<th>Laufzeit</th>
@ -22,7 +22,7 @@
</td>
<td>{{ node.position.lat }}</td>
<td>{{ node.position.lng }}</td>
<td>{{ node.battery }}%</td>
<td>{{ calculateBatteryPercentage(node.batteryVoltage, node.minVoltage, node.maxVoltage) }}%</td>
<td>{{ node.temperature }}°C</td>
<td>{{ node.runtime }}</td>
</tr>
@ -32,6 +32,9 @@
</template>
<script>
//folgende Mockdaten rausnehmen und mit axios requests abfragen
export default {
data() {
return {
@ -40,7 +43,9 @@ export default {
name: "XXXX-XXXX-XXXX-XXXX",
status: "ONLINE",
position: { lat: 40.7128, lng: 74.0012 },
battery: 98,
batteryVoltage: 3.9,
minVoltage: 3.0,
maxVoltage: 4.2,
temperature: 100,
runtime: "12h 30m 12s",
},
@ -48,7 +53,9 @@ export default {
name: "XXXX-XXXX-XXXX-XXXX",
status: "OFFLINE",
position: { lat: 40.7128, lng: 74.0012 },
battery: 19,
batteryVoltage: 3.2,
minVoltage: 3.0,
maxVoltage: 4.2,
temperature: 100,
runtime: "30m",
},
@ -56,7 +63,9 @@ export default {
name: "Localnode-3",
status: "ONLINE",
position: { lat: 40.7128, lng: 74.0012 },
battery: 66,
batteryVoltage: 3.7,
minVoltage: 3.0,
maxVoltage: 4.2,
temperature: 100,
runtime: "12h 30m 12s",
},
@ -64,7 +73,9 @@ export default {
name: "XXXX-XXXX-XXXX-XXXX",
status: "ONLINE",
position: { lat: 40.7128, lng: 74.0012 },
battery: 79,
batteryVoltage: 3.8,
minVoltage: 3.0,
maxVoltage: 4.2,
temperature: 100,
runtime: "12h 30m 12s",
},
@ -72,7 +83,9 @@ export default {
name: "XXXX-XXXX-XXXX-XXXX",
status: "ONLINE",
position: { lat: 40.7128, lng: 74.0012 },
battery: 10,
batteryVoltage: 3.1,
minVoltage: 3.0,
maxVoltage: 4.2,
temperature: 100,
runtime: "12h 30m 12s",
},
@ -80,7 +93,9 @@ export default {
name: "XXXX-XXXX-XXXX-XXXX",
status: "OFFLINE",
position: { lat: 40.7128, lng: 74.0012 },
battery: 0,
batteryVoltage: 3.0,
minVoltage: 3.0,
maxVoltage: 4.2,
temperature: 100,
runtime: "12h 30m 12s",
},
@ -88,36 +103,49 @@ export default {
name: "XXXX-XXXX-XXXX-XXXX",
status: "ONLINE",
position: { lat: 40.7128, lng: 74.0012 },
battery: 56,
batteryVoltage: 3.6,
minVoltage: 3.0,
maxVoltage: 4.2,
temperature: 100,
runtime: "12h 30m 12s",
},
],
};
},
methods: {
calculateBatteryPercentage(currentVoltage, minVoltage, maxVoltage) {
if (currentVoltage <= minVoltage) {
return 0;
} else if (currentVoltage >= maxVoltage) {
return 100;
} else {
return ((currentVoltage - minVoltage) / (maxVoltage - minVoltage) * 100).toFixed(2);
}
}
}
};
</script>
<style scoped>
.table-container {
background-color: white;
padding: 0.5rem 1rem; /* Reduce top padding to 0.5rem */
margin: 0 auto; /* Remove margin at the top, keep it centered horizontally */
width: 100%; /* Full width of parent */
overflow-x: auto; /* Allow horizontal scroll if necessary */
padding: 0.5rem 1rem;
margin: 0 auto;
width: 100%;
overflow-x: auto;
}
.responsive-table {
width: 100%; /* Full width */
border-collapse: collapse; /* Ensure tight borders */
margin: 0; /* Remove margin at the top of the table */
table-layout: auto; /* Auto layout for slimmer columns */
width: 100%;
border-collapse: collapse;
margin: 0;
table-layout: auto;
}
.responsive-table th,
.responsive-table td {
padding: 0.5rem; /* Maintain slim padding */
text-align: center; /* Center text */
padding: 0.5rem;
text-align: center;
border-bottom: 1px solid #ddd;
}
@ -126,7 +154,7 @@ export default {
}
.responsive-table tr:nth-child(even) {
background-color: #f9f9f9; /* Striped rows */
background-color: #f9f9f9;
}
.status-online {

View file

@ -5,8 +5,12 @@ export interface Node {
coordla: number;
coordlong: number;
temperature: number;
battery: number;
runtime: number;
batteryMinimum: number;
batteryCurrent: number;
batteryMaximum: number;
voltage: number;
uptime: number;
group: string;
}
export interface NodeGroup {