Updated RabbitMq to receive messages from Salidomo

Fixed bug in front-end when changing role from partner to client
Sorted installation view (alarms first)
This commit is contained in:
Noe 2024-05-10 19:16:16 +02:00
parent 8646790824
commit cba04ba01c
6 changed files with 114 additions and 13 deletions

View File

@ -57,9 +57,9 @@ public static class RabbitMqManager
if (receivedStatusMessage != null)
{
Console.WriteLine("----------------------------------------------");
Console.WriteLine("Received a message from installation: " + receivedStatusMessage.InstallationId + " and status is: " + receivedStatusMessage.Status);
int installationId = (int)Db.Installations.Where(f => f.Product == 0 && f.S3BucketId == receivedStatusMessage.InstallationId).Select(f => f.Id).FirstOrDefault();
int installationId = (int)Db.Installations.Where(f => f.Product == receivedStatusMessage.Product && f.S3BucketId == receivedStatusMessage.InstallationId).Select(f => f.Id).FirstOrDefault();
Console.WriteLine("Received a message from installation: " + installationId + " , product is: "+receivedStatusMessage.Product+ " and status is: " + receivedStatusMessage.Status);
//This is a heartbit message, just update the timestamp for this installation.
//There is no need to notify the corresponding front-ends.
@ -77,7 +77,7 @@ public static class RabbitMqManager
{
Warning newWarning = new Warning
{
InstallationId = receivedStatusMessage.InstallationId,
InstallationId = installationId,
Description = warning.Description,
Date = warning.Date,
Time = warning.Time,
@ -85,7 +85,7 @@ public static class RabbitMqManager
Seen = false
};
//Create a new warning and add it to the database
Db.HandleWarning(newWarning, receivedStatusMessage.InstallationId);
Db.HandleWarning(newWarning, installationId);
}
}
@ -93,12 +93,12 @@ public static class RabbitMqManager
//Traverse the Alarm list, and store each of them to the database
if (receivedStatusMessage.Alarms != null)
{
Console.WriteLine("Add an alarm for installation "+receivedStatusMessage.InstallationId);
Console.WriteLine("Add an alarm for installation "+installationId);
foreach (var alarm in receivedStatusMessage.Alarms)
{
Error newError = new Error
{
InstallationId = receivedStatusMessage.InstallationId,
InstallationId = installationId,
Description = alarm.Description,
Date = alarm.Date,
Time = alarm.Time,
@ -106,7 +106,7 @@ public static class RabbitMqManager
Seen = false
};
//Create a new error and add it to the database
Db.HandleError(newError, receivedStatusMessage.InstallationId);
Db.HandleError(newError, installationId);
}
}
}

View File

@ -16,8 +16,10 @@ dotnet publish \
-r linux-x64
echo -e "\n============================ Deploy ============================\n"
ip_addresses=("10.2.3.115" "10.2.3.104" "10.2.4.33" "10.2.4.32" "10.2.4.36" "10.2.4.35" "10.2.4.154" "10.2.4.113" "10.2.4.29")
#ip_addresses=("10.2.3.115" "10.2.3.104" "10.2.4.33" "10.2.4.32" "10.2.4.36" "10.2.4.35" "10.2.4.154" "10.2.4.113" "10.2.4.29")
#ip_addresses=("10.2.4.154" "10.2.4.29")
ip_addresses=("10.2.3.115" "10.2.3.104" "10.2.4.33" "10.2.4.32" "10.2.4.36" "10.2.4.35" "10.2.4.154" "10.2.4.29")
for ip_address in "${ip_addresses[@]}"; do

View File

@ -1,4 +1,4 @@
#define Amax
#undef Amax
#undef GridLimit
using System.IO.Compression;
@ -486,6 +486,7 @@ internal static class Program
var returnedStatus = new StatusMessage
{
InstallationId = installationId,
Product = 0,
Status = salimaxAlarmsState,
Type = MessageType.AlarmOrWarning,
Alarms = alarmList,

View File

@ -25,9 +25,29 @@ export const fetchDailyData = (
if (r.status === 404) {
return Promise.resolve(FetchResult.notAvailable);
} else if (r.status === 200) {
const text = await r.text();
// const text = await r.text();
const csvtext = await r.text(); // Assuming the server returns the Base64 encoded ZIP file as text
//const response = await fetch(url); // Fetch the resource from the server
const contentEncoding = r.headers.get('content-type');
if (contentEncoding != 'application/base64; charset=utf-8') {
return parseCsv(csvtext);
}
const byteArray = Uint8Array.from(atob(csvtext), (c) =>
c.charCodeAt(0)
);
//Decompress the byte array using JSZip
const zip = await JSZip.loadAsync(byteArray);
// Assuming the CSV file is named "data.csv" inside the ZIP archive
const csvContent = await zip.file('data.csv').async('text');
return parseCsv(csvContent);
//console.log(parseCsv(text));
return parseCsv(text);
//return parseCsv(text);
} else {
return Promise.resolve(FetchResult.notAvailable);
}

View File

@ -135,6 +135,33 @@ function InstallationTabs() {
)
}
]
: currentUser.userType == UserType.partner
? [
{
value: 'live',
label: <FormattedMessage id="live" defaultMessage="Live" />
},
{
value: 'overview',
label: <FormattedMessage id="overview" defaultMessage="Overview" />
},
{
value: 'batteryview',
label: (
<FormattedMessage
id="batteryview"
defaultMessage="Battery View"
/>
)
},
{
value: 'information',
label: (
<FormattedMessage id="information" defaultMessage="Information" />
)
}
]
: [
{
value: 'live',
@ -219,7 +246,8 @@ function InstallationTabs() {
)
}
]
: [
: currentUser.userType == UserType.partner
? [
{
value: 'list',
icon: <ListIcon id="mode-toggle-button-list-icon" />
@ -260,6 +288,37 @@ function InstallationTabs() {
}
]
: [
{
value: 'list',
icon: <ListIcon id="mode-toggle-button-list-icon" />
},
{
value: 'tree',
icon: <AccountTreeIcon id="mode-toggle-button-tree-icon" />
},
{
value: 'live',
label: <FormattedMessage id="live" defaultMessage="Live" />
},
{
value: 'overview',
label: (
<FormattedMessage id="overview" defaultMessage="Overview" />
)
},
{
value: 'information',
label: (
<FormattedMessage
id="information"
defaultMessage="Information"
/>
)
}
]
: [
{
value: 'list',
icon: <ListIcon id="mode-toggle-button-list-icon" />

View File

@ -9,11 +9,30 @@ import { InstallationsContext } from 'src/contexts/InstallationsContextProvider'
import { Route, Routes } from 'react-router-dom';
import routes from '../../../Resources/routes.json';
import Folder from './Folder';
import { WebSocketContext } from '../../../contexts/WebSocketContextProvider';
function InstallationTree() {
const { foldersAndInstallations, fetchAllFoldersAndInstallations } =
useContext(InstallationsContext);
const webSocketContext = useContext(WebSocketContext);
const { getStatus } = webSocketContext;
const sortedInstallations = [...foldersAndInstallations].sort((a, b) => {
// Compare the status field of each installation and sort them based on the status.
//Installations with alarms go first
let a_status = getStatus(a.id);
let b_status = getStatus(b.id);
if (a_status > b_status) {
return -1;
}
if (a_status < b_status) {
return 1;
}
return 0;
});
useEffect(() => {
fetchAllFoldersAndInstallations();
}, []);
@ -23,7 +42,7 @@ function InstallationTree() {
return (
node.parentId == parent_id && (
<CustomTreeItem node={node} parent_id={parent_id}>
{foldersAndInstallations.map((subnode) => {
{sortedInstallations.map((subnode) => {
return (
subnode != node &&
subnode.parentId == node.id && (