diff --git a/csharp/App/Backend/Backend.csproj b/csharp/App/Backend/Backend.csproj index 999e039c1..0078c9897 100644 --- a/csharp/App/Backend/Backend.csproj +++ b/csharp/App/Backend/Backend.csproj @@ -226,8 +226,8 @@ - - - + + + diff --git a/csharp/App/Backend/Controller.cs b/csharp/App/Backend/Controller.cs index 9feff6d72..67cce6e07 100644 --- a/csharp/App/Backend/Controller.cs +++ b/csharp/App/Backend/Controller.cs @@ -54,6 +54,8 @@ public class Controller : ControllerBase : Unauthorized(); } + + [HttpGet(nameof(CreateWebSocket))] public async Task CreateWebSocket(Token authToken) { @@ -81,6 +83,23 @@ public class Controller : ControllerBase //Handle the WebSocket connection await WebsocketManager.HandleWebSocketConnection(webSocket); } + + [HttpGet(nameof(GetAllErrorsForInstallation))] + public ActionResult> GetAllErrorsForInstallation(Int64 id, Token authToken) + { + var user = Db.GetSession(authToken)?.User; + if (user == null) + return Unauthorized(); + + var installation = Db.GetInstallationById(id); + + if (installation is null || !user.HasAccessTo(installation)) + return Unauthorized(); + + return Db.Errors + .Where(error => error.InstallationId == id) + .ToList(); + } [HttpGet(nameof(GetUserById))] public ActionResult GetUserById(Int64 id, Token authToken) diff --git a/csharp/App/Backend/DataTypes/Error.cs b/csharp/App/Backend/DataTypes/Error.cs new file mode 100644 index 000000000..1d10bf2ff --- /dev/null +++ b/csharp/App/Backend/DataTypes/Error.cs @@ -0,0 +1,14 @@ +using SQLite; + +namespace InnovEnergy.App.Backend.DataTypes; + +public class Error +{ + [PrimaryKey, AutoIncrement] + public Int64 Id { get; set; } + public Int64 InstallationId { get; set; } + public String ErrorDescription { get; set; } = null!; + public DateTime CreatedAt { get; set; } + public String DeviceCreatedTheError { get; set; } = null!; + public Boolean Seen { get; set; } +} \ No newline at end of file diff --git a/csharp/App/Backend/DataTypes/Methods/Folder.cs b/csharp/App/Backend/DataTypes/Methods/Folder.cs index f2595d00b..b6f8afd78 100644 --- a/csharp/App/Backend/DataTypes/Methods/Folder.cs +++ b/csharp/App/Backend/DataTypes/Methods/Folder.cs @@ -5,7 +5,6 @@ namespace InnovEnergy.App.Backend.DataTypes.Methods; public static class FolderMethods { - public static IEnumerable UsersWithAccess(this Folder folder) { var direct = folder.UsersWithDirectAccess(); diff --git a/csharp/App/Backend/DataTypes/Methods/Installation.cs b/csharp/App/Backend/DataTypes/Methods/Installation.cs index 4b2342f85..93ecee76e 100644 --- a/csharp/App/Backend/DataTypes/Methods/Installation.cs +++ b/csharp/App/Backend/DataTypes/Methods/Installation.cs @@ -141,7 +141,7 @@ public static class InstallationMethods foreach (var orderNumber in installation.OrderNumbers.Split(",")) { var rel = relations.FirstOrDefault(i => i.OrderNumber == orderNumber); - if ( rel != null) relations.Remove(rel); + if ( rel != null) {relations.Remove(rel); continue;} var o2I = new OrderNumber2Installation { OrderNumber = orderNumber, diff --git a/csharp/App/Backend/DataTypes/TreeNode.cs b/csharp/App/Backend/DataTypes/TreeNode.cs index 5613fbbdf..a19d05598 100644 --- a/csharp/App/Backend/DataTypes/TreeNode.cs +++ b/csharp/App/Backend/DataTypes/TreeNode.cs @@ -5,7 +5,7 @@ namespace InnovEnergy.App.Backend.DataTypes; public abstract partial class TreeNode { [PrimaryKey, AutoIncrement] - public virtual Int64 Id { get; set; } + public Int64 Id { get; set; } public virtual String Name { get; set; } = ""; // overridden by User (unique) public String Information { get; set; } = ""; // unstructured random info diff --git a/csharp/App/Backend/Database/Create.cs b/csharp/App/Backend/Database/Create.cs index 627b5a191..924e1c4aa 100644 --- a/csharp/App/Backend/Database/Create.cs +++ b/csharp/App/Backend/Database/Create.cs @@ -20,6 +20,11 @@ public static partial class Db return Insert(installation); } + public static Boolean Create(Error error) + { + return Insert(error); + } + public static Boolean Create(Folder folder) { return Insert(folder); @@ -49,4 +54,30 @@ public static partial class Db { return Insert(o2i); } + + public static void HandleError(Error newError,int installationId) + { + //Find the total number of errors for this installation + var totalErrors = Errors.Count(error => error.InstallationId == installationId); + + //If there are 100 errors, remove the one with the oldest timestamp + if (totalErrors == 100) + { + var oldestError = + Errors.Where(error => error.InstallationId == installationId) + .OrderBy(error => error.CreatedAt) + .FirstOrDefault(); + + //Remove the old error + Delete(oldestError); + + //Add the new error + Create(newError); + } + else + { + Console.WriteLine("---------------Added the new Error to the database-----------------"); + Create(newError); + } + } } \ No newline at end of file diff --git a/csharp/App/Backend/Database/Db.cs b/csharp/App/Backend/Database/Db.cs index b8d86c071..f4255a677 100644 --- a/csharp/App/Backend/Database/Db.cs +++ b/csharp/App/Backend/Database/Db.cs @@ -15,21 +15,36 @@ namespace InnovEnergy.App.Backend.Database; public static partial class Db { - // internal const String DbPath = "./db.sqlite"; + private static SQLiteConnection Connection { get; } = InitConnection(); - private static SQLiteConnection Connection { get; } = ((Func)(() => + private static SQLiteConnection InitConnection() { - var latestDb = new DirectoryInfo(@"DbBackups").GetFiles() - .OrderBy(f => f.LastWriteTime) - .Last().Name; + var latestDb = new DirectoryInfo("DbBackups") + .GetFiles() + .OrderBy(f => f.LastWriteTime) + .Last().Name; - var fileConnection = new SQLiteConnection("DbBackups/"+latestDb); + //This is the file connection from the DbBackups folder + var fileConnection = new SQLiteConnection("DbBackups/" + latestDb); + + //Create a table if it does not exist + fileConnection.CreateTable(); + fileConnection.CreateTable(); + fileConnection.CreateTable(); + fileConnection.CreateTable(); + fileConnection.CreateTable(); + fileConnection.CreateTable(); + fileConnection.CreateTable(); + fileConnection.CreateTable(); + + return CopyDbToMemory(fileConnection); + } - Console.Out.Write(latestDb); + private static SQLiteConnection CopyDbToMemory(SQLiteConnection fileConnection) + { var memoryConnection = new SQLiteConnection(":memory:"); - // fileConnection.Backup(memoryConnection.DatabasePath); - + //Create a table if it does not exist in main memory memoryConnection.CreateTable(); memoryConnection.CreateTable(); memoryConnection.CreateTable(); @@ -37,18 +52,21 @@ public static partial class Db memoryConnection.CreateTable(); memoryConnection.CreateTable(); memoryConnection.CreateTable(); - - fileConnection.Table ().ForEach(memoryConnection.Insert); - fileConnection.Table ().ForEach(memoryConnection.Insert); - fileConnection.Table ().ForEach(memoryConnection.Insert); - fileConnection.Table ().ForEach(memoryConnection.Insert); - fileConnection.Table ().ForEach(memoryConnection.Insert); - fileConnection.Table ().ForEach(memoryConnection.Insert); - fileConnection.Table().ForEach(memoryConnection.Insert); + memoryConnection.CreateTable(); + //Copy all the existing tables from the disk to main memory + fileConnection.Table().ForEach(memoryConnection.Insert); + fileConnection.Table().ForEach(memoryConnection.Insert); + fileConnection.Table().ForEach(memoryConnection.Insert); + fileConnection.Table().ForEach(memoryConnection.Insert); + fileConnection.Table().ForEach(memoryConnection.Insert); + fileConnection.Table().ForEach(memoryConnection.Insert); + fileConnection.Table().ForEach(memoryConnection.Insert); + fileConnection.Table().ForEach(memoryConnection.Insert); + return memoryConnection; - }))(); - + } + public static void BackupDatabase() { var filename = "db-" + DateTimeOffset.UtcNow.ToUnixTimeSeconds() + ".sqlite"; @@ -62,17 +80,16 @@ public static partial class Db public static TableQuery FolderAccess => Connection.Table(); public static TableQuery InstallationAccess => Connection.Table(); public static TableQuery OrderNumber2Installation => Connection.Table(); - - public static void Init() - { + public static TableQuery Errors => Connection.Table(); + + public static void Init(){ // used to force static constructor + //Since this class is static, we call Init method from the Program.cs to initialize all the fields of the class } - + //This is the constructor of the class static Db() { - // on startup create/migrate tables - Connection.RunInTransaction(() => { Connection.CreateTable(); @@ -82,6 +99,7 @@ public static partial class Db Connection.CreateTable(); Connection.CreateTable(); Connection.CreateTable(); + Connection.CreateTable(); }); Observable.Interval(TimeSpan.FromHours(0.5)) diff --git a/csharp/App/Backend/Database/Delete.cs b/csharp/App/Backend/Database/Delete.cs index 660d61539..abefabadd 100644 --- a/csharp/App/Backend/Database/Delete.cs +++ b/csharp/App/Backend/Database/Delete.cs @@ -34,6 +34,20 @@ public static partial class Db return delete>0; } } + + public static Boolean Delete(Error errorToDelete) + { + var deleteSuccess = RunTransaction(DeleteError); + if (deleteSuccess) + BackupDatabase(); + return deleteSuccess; + + + Boolean DeleteError() + { + return Errors.Delete(error => error.Id == errorToDelete.Id) >0; + } + } public static Boolean Delete(Installation installation) { diff --git a/csharp/App/Backend/Database/Update.cs b/csharp/App/Backend/Database/Update.cs index 094487552..16d9d76b0 100644 --- a/csharp/App/Backend/Database/Update.cs +++ b/csharp/App/Backend/Database/Update.cs @@ -33,7 +33,4 @@ public static partial class Db return Update(obj: user); } - - - } \ No newline at end of file diff --git a/csharp/App/Backend/Websockets/StatusMessage.cs b/csharp/App/Backend/Websockets/StatusMessage.cs index 074ac71b0..244f123be 100644 --- a/csharp/App/Backend/Websockets/StatusMessage.cs +++ b/csharp/App/Backend/Websockets/StatusMessage.cs @@ -1,6 +1,9 @@ public class StatusMessage { - public required int InstallationId { get; init; } - public required int Status { get; init; } + public required int InstallationId { get; init; } + public required int Status { get; init; } + public DateTime CreatedAt { get; set; } + public String Error { get; init; } = null!; + public String DeviceCreatedTheError { get; init; } = null!; } \ No newline at end of file diff --git a/csharp/App/Backend/Websockets/WebsockerManager.cs b/csharp/App/Backend/Websockets/WebsockerManager.cs index b2a1f2924..989441e08 100644 --- a/csharp/App/Backend/Websockets/WebsockerManager.cs +++ b/csharp/App/Backend/Websockets/WebsockerManager.cs @@ -5,6 +5,7 @@ using System.Net.WebSockets; using System.Text; using System.Text.Json; using InnovEnergy.App.Backend.Database; +using InnovEnergy.App.Backend.DataTypes; using RabbitMQ.Client; using RabbitMQ.Client.Events; @@ -19,7 +20,6 @@ public static class WebsocketManager public static void InformInstallationsToSubscribeToRabbitMq() { - //var installationIps = new List { "10.2.3.115" }; var installationIps = Db.Installations.Select(inst => inst.VpnIp).ToList(); Console.WriteLine("Count is "+installationIps.Count); var maxRetransmissions = 2; @@ -83,13 +83,31 @@ public static class WebsocketManager lock (InstallationConnections) { - // Process the received message + //Consumer received a message if (receivedStatusMessage != null) { Console.WriteLine("Received a message from installation: " + receivedStatusMessage.InstallationId + " and status is: " + receivedStatusMessage.Status); Console.WriteLine("----------------------------------------------"); Console.WriteLine("Update installation connection table"); var installationId = receivedStatusMessage.InstallationId; + + //This is an error message + if (receivedStatusMessage.Status==2) + { + Console.WriteLine("-----------------------New error-----------------------"); + + Error newError = new Error + { + InstallationId = receivedStatusMessage.InstallationId, + ErrorDescription = receivedStatusMessage.Error, + CreatedAt = receivedStatusMessage.CreatedAt, + DeviceCreatedTheError = receivedStatusMessage.DeviceCreatedTheError, + Seen = false + }; + //Create a new error and add it to the database + Db.HandleError(newError,receivedStatusMessage.InstallationId); + + } if (!InstallationConnections.ContainsKey(installationId)) { diff --git a/csharp/App/SaliMax/src/MiddlewareClasses/StatusMessage.cs b/csharp/App/SaliMax/src/MiddlewareClasses/StatusMessage.cs index 8af41f9a3..1faf68d8e 100644 --- a/csharp/App/SaliMax/src/MiddlewareClasses/StatusMessage.cs +++ b/csharp/App/SaliMax/src/MiddlewareClasses/StatusMessage.cs @@ -3,6 +3,10 @@ namespace InnovEnergy.App.SaliMax.MiddlewareClasses; public class StatusMessage { - public required int InstallationId { get; init; } - public required int Status { get; init; } + + public required int InstallationId { get; init; } + public required int Status { get; init; } + public DateTime CreatedAt { get; set; } + public String Error { get; set; } = null!; + public String DeviceCreatedTheError { get; set; } = null!; } \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 20ff268d9..c9135ab20 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; @@ -265,10 +266,14 @@ internal static class Program { _subscribeToQueueForTheFirstTime = true; SubscribeToQueue(currentSalimaxState, s3Bucket); + + if (_subscribedToQueue && currentSalimaxState != _prevSalimaxState) + { + _prevSalimaxState = currentSalimaxState; + } } - //If already subscribed to the queue and the status has been changed, update the queue - if (_subscribedToQueue && currentSalimaxState != _prevSalimaxState) + else if (_subscribedToQueue && currentSalimaxState != _prevSalimaxState) { _prevSalimaxState = currentSalimaxState; if (s3Bucket != null) @@ -343,12 +348,18 @@ internal static class Program private static void InformMiddleware(String? bucket, int status) { int.TryParse(bucket[0].ToString(), out var installationId); - var jsonObject = new StatusMessage { InstallationId = installationId, - Status = status + Status = status, }; + + if (status == 2) + { + jsonObject.CreatedAt = DateTime.Now; + jsonObject.Error = "Battery Temperature High"; + jsonObject.DeviceCreatedTheError = "Battery/1"; + } var message = JsonSerializer.Serialize(jsonObject); var body = Encoding.UTF8.GetBytes(message); diff --git a/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs b/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs index 86a334c3b..5df7597a0 100644 --- a/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs +++ b/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs @@ -1,3 +1,4 @@ +using System.ComponentModel; using InnovEnergy.Lib.Devices.Trumpf.SystemControl; using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes; using InnovEnergy.Lib.Units.Composite; @@ -18,6 +19,9 @@ public class AcDcDevicesRecord public SystemControlRegisters? SystemControl { get; } public IReadOnlyList Devices { get; init; } + //public IEnumerable Alarms => new []{AlarmMessage.BatteryOvervoltage}; //Devices.SelectMany(d => d.Status.Alarms).Distinct(); + //public IEnumerable Warnings => new []{WarningMessage.TempDerating}; //Devices.SelectMany(d => d.Status.Warnings).Distinct(); + public IEnumerable Alarms => Devices.SelectMany(d => d.Status.Alarms).Distinct(); public IEnumerable Warnings => Devices.SelectMany(d => d.Status.Warnings).Distinct(); diff --git a/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/WarningMessage.cs b/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/WarningMessage.cs index 11ec4cdd2..ead25e819 100644 --- a/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/WarningMessage.cs +++ b/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/WarningMessage.cs @@ -10,7 +10,7 @@ public enum WarningMessage : UInt16 { NoWarning = 00000, - /* + // these warnings are not official (not in the manual), and they seem to collide with the DCDC warnings // so I commented them @@ -28,5 +28,5 @@ public enum WarningMessage : UInt16 RuntimeEeprom = 11023, //AC-DC module warning Overcurrent = 11024 //Overcurrent handling is active - */ + } \ No newline at end of file diff --git a/typescript/frontend-marios2/src/Resources/axiosConfig.tsx b/typescript/frontend-marios2/src/Resources/axiosConfig.tsx index b9d24d440..6069ad19f 100644 --- a/typescript/frontend-marios2/src/Resources/axiosConfig.tsx +++ b/typescript/frontend-marios2/src/Resources/axiosConfig.tsx @@ -1,13 +1,13 @@ import axios from 'axios'; export const axiosConfigWithoutToken = axios.create({ - baseURL: 'https://monitor.innov.energy/api' - // baseURL: 'http://127.0.0.1:7087/api' + //baseURL: 'https://monitor.innov.energy/api' + baseURL: 'http://127.0.0.1:7087/api' }); const axiosConfig = axios.create({ - baseURL: 'https://monitor.innov.energy/api' - //baseURL: 'http://127.0.0.1:7087/api' + //baseURL: 'https://monitor.innov.energy/api' + baseURL: 'http://127.0.0.1:7087/api' }); axiosConfig.defaults.params = {}; diff --git a/typescript/frontend-marios2/src/content/dashboards/Installations/Installation.tsx b/typescript/frontend-marios2/src/content/dashboards/Installations/Installation.tsx index 377f19829..7c0e454ce 100644 --- a/typescript/frontend-marios2/src/content/dashboards/Installations/Installation.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/Installations/Installation.tsx @@ -28,7 +28,6 @@ import { extractValues, TopologyValues } from 'src/content/dashboards/Log/graph.util'; -import { Notification } from 'src/interfaces/S3Types'; import { WebSocketContext } from 'src/contexts/WebSocketContextProvider'; import Topology from '../Topology/Topology'; import { FormattedMessage } from 'react-intl'; @@ -62,8 +61,6 @@ function Installation(props: singleInstallationProps) { deleteInstallation } = installationContext; - const [warnings, setWarnings] = useState([]); - const [errors, setErrors] = useState([]); const [errorLoadingS3Data, setErrorLoadingS3Data] = useState(false); const webSocketsContext = useContext(WebSocketContext); const { getStatus } = webSocketsContext; @@ -153,9 +150,6 @@ function Installation(props: singleInstallationProps) { return; } - const newWarnings: Notification[] = []; - const newErrors: Notification[] = []; - if ( res === FetchResult.notAvailable || res === FetchResult.tryLater @@ -681,9 +675,8 @@ function Installation(props: singleInstallationProps) { {currentTab === 'live' && } {currentTab === 'log' && ( )} diff --git a/typescript/frontend-marios2/src/content/dashboards/Log/Log.tsx b/typescript/frontend-marios2/src/content/dashboards/Log/Log.tsx index 4a0267271..2e3a06f35 100644 --- a/typescript/frontend-marios2/src/content/dashboards/Log/Log.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/Log/Log.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { Alert, Card, @@ -14,26 +14,49 @@ import { TableRow, useTheme } from '@mui/material'; -import WarningIcon from '@mui/icons-material/Warning'; import Typography from '@mui/material/Typography'; -import { Notification } from 'src/interfaces/S3Types'; import { FormattedMessage } from 'react-intl'; import ErrorIcon from '@mui/icons-material/Error'; +import axiosConfig from '../../../Resources/axiosConfig'; +import { AxiosError, AxiosResponse } from 'axios/index'; +import routes from '../../../Resources/routes.json'; +import { useNavigate } from 'react-router-dom'; +import { TokenContext } from '../../../contexts/tokenContext'; +import { ErrorMessage } from '../../../interfaces/S3Types'; interface LogProps { - warnings: Notification[]; - errors: Notification[]; errorLoadingS3Data: boolean; + id: number; } function Log(props: LogProps) { const theme = useTheme(); + //const [warnings, setWarnings] = useState([]); + const [errors, setErrors] = useState([]); + const navigate = useNavigate(); + const tokencontext = useContext(TokenContext); + const { removeToken } = tokencontext; + + useEffect(() => { + axiosConfig + .get(`/GetAllErrorsForInstallation?id=${props.id}`) + .then((res: AxiosResponse) => { + setErrors(res.data); + }) + .catch((err: AxiosError) => { + if (err.response && err.response.status == 401) { + removeToken(); + navigate(routes.login); + } + }); + }, []); return ( - {(props.errors.length > 0 || props.warnings.length > 0) && ( + {/* IT SHOULD BE {(errors.length > 0 || props.warnings.length > 0) && (*/} + {errors.length > 0 && ( @@ -43,25 +66,26 @@ function Log(props: LogProps) { - - - + + + + - + - {props.errors.map((error, index) => { + {errors.map((error, index) => { return ( @@ -82,9 +106,9 @@ function Log(props: LogProps) { color="text.primary" gutterBottom noWrap - sx={{ marginTop: '5px' }} + sx={{ marginTop: '5px', marginLeft: '-40px' }} > - {error.device} + {error.errorDescription} @@ -96,7 +120,7 @@ function Log(props: LogProps) { noWrap sx={{ marginTop: '5px' }} > - {error.description} + {error.deviceCreatedTheError} @@ -106,9 +130,9 @@ function Log(props: LogProps) { color="text.primary" gutterBottom noWrap - sx={{ marginTop: '5px' }} + sx={{ marginTop: '5px', marginLeft: '-40px' }} > - {error.date} + {error.createdAt} @@ -118,87 +142,87 @@ function Log(props: LogProps) { color="text.primary" gutterBottom noWrap - sx={{ marginTop: '5px' }} + sx={{ marginTop: '5px', marginLeft: '10px' }} > - {error.time} + {error.seen == false ? 'No' : 'Yes'} ); })} - {props.warnings.map((warning, index) => { - return ( - - - - - - - {warning.device} - - - - - {warning.description} - - - - - {warning.date} - - - - - {warning.time} - - - - ); - })} + {/*{props.warnings.map((warning, index) => {*/} + {/* return (*/} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + {/* {warning.device}*/} + {/* */} + {/* */} + {/* */} + {/* */} + {/* {warning.description}*/} + {/* */} + {/* */} + {/* */} + {/* */} + {/* {warning.date}*/} + {/* */} + {/* */} + {/* */} + {/* */} + {/* {warning.time}*/} + {/* */} + {/* */} + {/* */} + {/* );*/} + {/*})}*/} )} - {!props.errorLoadingS3Data && props.errors.length == 0 && ( + {!props.errorLoadingS3Data && errors.length == 0 && ( )} - {!props.errorLoadingS3Data && props.warnings.length == 0 && ( - - - - - )} + {/*{!props.errorLoadingS3Data && props.warnings.length == 0 && (*/} + {/* */} + {/* */} + {/* */} + {/* */} + {/*)}*/} diff --git a/typescript/frontend-marios2/src/content/dashboards/Log/fetchData.tsx b/typescript/frontend-marios2/src/content/dashboards/Log/fetchData.tsx deleted file mode 100644 index 0bc6f455d..000000000 --- a/typescript/frontend-marios2/src/content/dashboards/Log/fetchData.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { UnixTime } from '../../../dataCache/time'; -import { I_S3Credentials } from '../../../interfaces/S3Types'; -import { FetchResult } from '../../../dataCache/dataCache'; -import { DataRecord } from '../../../dataCache/data'; -import { S3Access } from '../../../dataCache/S3/S3Access'; -import { parseCsv } from './graph.util'; - -export const fetchData = ( - timestamp: UnixTime, - s3Credentials?: I_S3Credentials -): Promise> => { - const s3Path = `${timestamp.ticks}.csv`; - if (s3Credentials && s3Credentials.s3Bucket) { - const s3Access = new S3Access( - s3Credentials.s3Bucket, - s3Credentials.s3Region, - s3Credentials.s3Provider, - s3Credentials.s3Key, - s3Credentials.s3Secret - ); - return s3Access - .get(s3Path) - .then(async (r) => { - if (r.status === 404) { - return Promise.resolve(FetchResult.notAvailable); - } else if (r.status === 200) { - const text = await r.text(); - return parseCsv(text); - } else { - return Promise.resolve(FetchResult.notAvailable); - } - }) - .catch((e) => { - return Promise.resolve(FetchResult.tryLater); - }); - } -}; diff --git a/typescript/frontend-marios2/src/interfaces/S3Types.tsx b/typescript/frontend-marios2/src/interfaces/S3Types.tsx index 4f04962b6..b68ddc4b9 100644 --- a/typescript/frontend-marios2/src/interfaces/S3Types.tsx +++ b/typescript/frontend-marios2/src/interfaces/S3Types.tsx @@ -6,9 +6,10 @@ export interface I_S3Credentials { s3Bucket?: string; } -export interface Notification { - device: string; - description: string; - date: string; - time: string; +export interface ErrorMessage { + installationId: number; + createdAt: Date; + errorDescription: string; + deviceCreatedTheError: string; + seen: boolean; }