2nd Version with the complete UI and the first Version of cc+ .so

This commit is contained in:
2024-03-31 21:12:43 +02:00
parent 3fe818e144
commit a221b8f046
43 changed files with 2056 additions and 554 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/vrpmdvfrontend-30-03-2023.zip
/vrpmdvfrontend-vor_umbau_menu.zip

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"cmake.sourceDirectory": "/home/markus/git/vrpmdvweb/vrpmdvserver/rt_service"
}

28
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

View File

@@ -1 +1 @@
[{"id": "6920a93a-b37e-4077-954a-5daaf0c53d32", "created_at": "03/17/2024, 11:18", "name": "Monitoring1-123", "samplerate": 4000, "sampleperiod": 3, "downtime": 10, "owner": "Markus Lehr"}, {"id": "bd3ce27c-c641-4a39-b2d6-88fb4f739a23", "created_at": "03/18/2024, 15:58", "name": "Monitoring0815", "samplerate": 5000, "sampleperiod": 1, "downtime": 6, "owner": "markus lehr"}, {"id": "1088405b-8d47-4477-981b-baba924a8079", "created_at": "03/18/2024, 15:58", "name": "Monitorinh4711", "samplerate": 3500, "sampleperiod": 3, "downtime": 10, "owner": "markus lehr"}, {"id": "b649599e-c46c-4bc5-bf0a-252382623ac9", "created_at": "03/19/2024, 07:37", "name": "Monitoring123", "samplerate": 3750, "sampleperiod": 2, "downtime": 10, "owner": "Markus Lehr"}, {"id": "50701299-5d31-4205-9467-a7048b8da7c5", "created_at": "03/19/2024, 08:03", "name": "Monitoring-Monowell-195KW", "samplerate": 3750, "sampleperiod": 20, "downtime": 40, "owner": "Markus Lehr"}] [{"id": "6920a93a-b37e-4077-954a-5daaf0c53d32", "created_at": "03/17/2024, 11:18", "name": "Monitoring1-123", "samplerate": 4000, "sampleperiod": 3, "downtime": 10, "owner": "Markus Lehr", "monstate": "created"}, {"id": "bd3ce27c-c641-4a39-b2d6-88fb4f739a23", "created_at": "03/18/2024, 15:58", "name": "Monitoring0815", "samplerate": 5000, "sampleperiod": 1, "downtime": 6, "owner": "markus lehr", "monstate": "created"}, {"id": "1088405b-8d47-4477-981b-baba924a8079", "created_at": "03/18/2024, 15:58", "name": "Monitorinh4711", "samplerate": 3500, "sampleperiod": 3, "downtime": 10, "owner": "markus lehr", "monstate": "created"}, {"id": "b649599e-c46c-4bc5-bf0a-252382623ac9", "created_at": "03/19/2024, 07:37", "name": "Monitoring123", "samplerate": 3750, "sampleperiod": 2, "downtime": 10, "owner": "Markus Lehr", "monstate": "created"}, {"id": "50701299-5d31-4205-9467-a7048b8da7c5", "created_at": "03/19/2024, 08:03", "name": "Monitoring-Monowell-195KW", "samplerate": 3750, "sampleperiod": 20, "downtime": 40, "owner": "Markus Lehr", "monstate": "created"}, {"id": "5bcb2d00-d627-421c-9f6a-f282da83a426", "created_at": "03/26/2024, 17:36", "name": "M1", "samplerate": 3000, "sampleperiod": 10, "downtime": 40, "owner": "ML", "monstate": "created"}, {"id": "78fc59e2-446e-40d8-87d1-6cc4e33cb798", "created_at": "03/26/2024, 17:38", "name": "M2", "samplerate": 3000, "sampleperiod": 50, "downtime": 780, "owner": "ML", "monstate": "created"}]

File diff suppressed because one or more lines are too long

View File

@@ -22,7 +22,7 @@
<title> <title>
Markus Lehr | VR Predictive Maintenance Device. Markus Lehr | VR Predictive Maintenance Device.
</title> </title>
<script type="module" crossorigin src="/assets/index-ebf4aa2f.js"></script> <script type="module" crossorigin src="/assets/index-3c13134c.js"></script>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>

View File

@@ -48,9 +48,15 @@ import { VR_API_URL } from './env';
const API_URL = "https://api.fake-rest.refine.dev"; const API_URL = "https://api.fake-rest.refine.dev";
// Test URL
//const MONITORINGS_API_URL = 'http://127.0.0.1:5000/vrpmdvapi/1_0';
// Embedded URL
const MONITORINGS_API_URL = '/vrpmdvapi/1_0'; const MONITORINGS_API_URL = '/vrpmdvapi/1_0';
// .get(`${API_URL}/exams`) // .get(`${API_URL}/exams`)
const MONITORINGSTATUS_API_URL = 'http://127.0.0.1:5000/vrpmdvapi/1_0';
function App() { function App() {
return ( return (
<BrowserRouter> <BrowserRouter>

View File

@@ -1,14 +1,18 @@
import { Autocomplete, Box, InputAdornment, MenuItem, Select, TextField } from "@mui/material"; import { Autocomplete, Box, FormControl, FormLabel, InputAdornment, MenuItem, Select, Stack, TextField, ToggleButton, ToggleButtonGroup } from "@mui/material";
import { Create, NumberField, useAutocomplete } from "@refinedev/mui"; import { Create, NumberField, useAutocomplete } from "@refinedev/mui";
import { useForm } from "@refinedev/react-hook-form"; import { useForm } from "@refinedev/react-hook-form";
import { Controller } from "react-hook-form"; import { Controller } from "react-hook-form";
import { IMonitoring } from "./monitorings.types"; import { IMonitoring } from "./monitorings.types";
import { Group } from "@mui/icons-material";
import { MonitoringStatusEditChip } from "./status/monitoringstatusedit";
import { MonitoringStatusChip } from "./status/monitoringstatuschip";
export const MonitoringCreate = () => { export const MonitoringCreate = () => {
const { const {
saveButtonProps, saveButtonProps,
refineCore: { formLoading }, refineCore: { formLoading },
setValue,
register, register,
control, control,
formState: { errors }, formState: { errors },
@@ -23,6 +27,7 @@ export const MonitoringCreate = () => {
<Box <Box
component="form" component="form"
sx={{ display: "flex", flexDirection: "column" }} sx={{ display: "flex", flexDirection: "column" }}
gap={2}
autoComplete="off" autoComplete="off"
> >
<TextField <TextField
@@ -38,57 +43,91 @@ export const MonitoringCreate = () => {
label={"Name"} label={"Name"}
name="name" name="name"
/> />
<TextField <Stack direction="row" spacing={2} alignItems="center" justifyContent="space-between">
{...register("samplerate", { <TextField
required: "The samplerate is required", {...register("samplerate", {
})} required: "The samplerate is required",
error={!!(errors as any)?.samplerate} })}
helperText={(errors as any)?.samplerate?.message} error={!!(errors as any)?.samplerate}
margin="normal" helperText={(errors as any)?.samplerate?.message}
fullWidth margin="normal"
InputLabelProps={{ shrink: true }} fullWidth
type="number" InputLabelProps={{ shrink: true }}
label={"Samplerate"} type="number"
name="samplerate" label={"Samplerate"}
InputProps={{ name="samplerate"
endAdornment: InputProps={{
<InputAdornment position="end">hz</InputAdornment> endAdornment:
}} <InputAdornment position="end">hz</InputAdornment>
/> }}
<TextField />
{...register("sampleperiod", { <TextField
required: "The sampleperiod is required", {...register("sampleperiod", {
})} required: "The sampleperiod is required",
error={!!(errors as any)?.sampleperiod} })}
helperText={(errors as any)?.sampleperiod?.message} error={!!(errors as any)?.sampleperiod}
margin="normal" helperText={(errors as any)?.sampleperiod?.message}
fullWidth margin="normal"
InputLabelProps={{ shrink: true }} fullWidth
type="number" InputLabelProps={{ shrink: true }}
label={"Sampleperiod"} type="number"
name="sampleperiod" label={"Sampleperiod"}
InputProps={{ name="sampleperiod"
endAdornment: InputProps={{
<InputAdornment position="end">s</InputAdornment> endAdornment:
}} <InputAdornment position="end">s</InputAdornment>
/> }}
<TextField />
{...register("downtime", { <TextField
required: "The downtime is required", {...register("downtime", {
})} required: "The downtime is required",
error={!!(errors as any)?.downtime} })}
helperText={(errors as any)?.downtime?.message} error={!!(errors as any)?.downtime}
margin="normal" helperText={(errors as any)?.downtime?.message}
fullWidth margin="normal"
InputLabelProps={{ shrink: true }} fullWidth
type="number" InputLabelProps={{ shrink: true }}
label={"Downtime"} type="number"
name="downtime" label={"Downtime"}
InputProps={{ name="downtime"
endAdornment: InputProps={{
<InputAdornment position="end">s</InputAdornment> endAdornment:
}} <InputAdornment position="end">s</InputAdornment>
/> }}
/>
</Stack>
<FormControl>
<Controller
control={control}
name="status"
defaultValue="off"
render={({ field }) => (
<ToggleButtonGroup
id="Status"
{...field}
exclusive
color="primary"
onChange={(_, newValue) => {
setValue("status", newValue, {
shouldValidate: true,
});
return newValue;
}}
>
<ToggleButton value={"started"}>
{"Started"}
</ToggleButton>
<ToggleButton value={"stopped"}>
{"Stopped"}
</ToggleButton>
<ToggleButton value={"off"}>
{"Deactivated"}
</ToggleButton>
</ToggleButtonGroup>
)}
/>
</FormControl>
<TextField <TextField
{...register("owner", { {...register("owner", {
required: "The downtime is required", required: "The downtime is required",
@@ -107,6 +146,61 @@ export const MonitoringCreate = () => {
); );
}; };
//----------- new
// <Controller
// control={control}
// name="category"
// rules={{ required: "This field is required" }}
// // eslint-disable-next-line
// defaultValue={null as any}
// render={({ field }) => (
// <Autocomplete
// {...categoryAutocompleteProps}
// {...field}
// onChange={(_, value) => {
// field.onChange(value);
// }}
// getOptionLabel={(item) => {
// return (
// categoryAutocompleteProps?.options?.find(
// (p) =>
// p?.id?.toString() ===
// item?.id?.toString(),
// )?.title ?? ""
// );
// }}
// isOptionEqualToValue={(option, value) =>
// value === undefined ||
// option?.id?.toString() === value?.id?.toString()
// }
// renderInput={(params) => (
// <TextField
// {...params}
// label="Category"
// margin="normal"
// variant="outlined"
// error={!!(errors as any)?.category?.id}
// helperText={
// (errors as any)?.category?.id?.message
// }
// required
// />
// )}
// />
// )}
// />
//---------------
// <Controller
// name="status"
// control={control}
// rules={{ required: true }}
// render={({ field }) => <MonitoringStatusChip value={field.value} />}
// />

View File

@@ -11,12 +11,16 @@ import {
} from "@refinedev/mui"; } from "@refinedev/mui";
import React from "react"; import React from "react";
import { IMonitoring } from "./monitorings.types"; import { IMonitoring } from "./monitorings.types";
import { MonitoringStatus } from "./status/monitoringstatus";
import { MonitoringStatusEditChip } from "./status/monitoringstatusedit";
import { useUpdate } from "@refinedev/core";
export const MonitoringList = () => { export const MonitoringList = () => {
const dataProvider = "monitorings";
const { dataGridProps } = useDataGrid<IMonitoring>({ const { dataGridProps } = useDataGrid<IMonitoring>({
syncWithLocation: true, syncWithLocation: true,
dataProviderName: "monitorings", dataProviderName: dataProvider,
pagination: { pagination: {
mode: "client", mode: "client",
pageSize: 10, pageSize: 10,
@@ -34,6 +38,9 @@ export const MonitoringList = () => {
// }, // },
// }); // });
const { mutate } = useUpdate();
const columns = React.useMemo<GridColDef<IMonitoring>[]>( const columns = React.useMemo<GridColDef<IMonitoring>[]>(
() => [ () => [
{ {
@@ -43,12 +50,6 @@ export const MonitoringList = () => {
type:"string", type:"string",
minWidth: 250, minWidth: 250,
}, },
{
field: "id",
headerName: "ID",
type: "string",
minWidth: 300,
},
{ {
field: "created_at", field: "created_at",
flex: 1, flex: 1,
@@ -61,7 +62,7 @@ export const MonitoringList = () => {
{ {
field: "samplerate", field: "samplerate",
flex: 0.3, flex: 0.3,
headerName: "Samplerate in Hz", headerName: "Samplerate/Hz",
renderCell: function render({ row }) { renderCell: function render({ row }) {
return ( return (
<NumberField <NumberField
@@ -79,7 +80,7 @@ export const MonitoringList = () => {
{ {
field: "sampleperiod", field: "sampleperiod",
flex: 0.3, flex: 0.3,
headerName: "Period in s", headerName: "Period/s",
renderCell: function render({ row }) { renderCell: function render({ row }) {
return ( return (
<NumberField <NumberField
@@ -97,7 +98,7 @@ export const MonitoringList = () => {
{ {
field: "downtime", field: "downtime",
flex: 0.3, flex: 0.3,
headerName: "Downtime in s", headerName: "Downtime/s",
renderCell: function render({ row }) { renderCell: function render({ row }) {
return ( return (
<NumberField <NumberField
@@ -119,6 +120,25 @@ export const MonitoringList = () => {
type:"string", type:"string",
minWidth: 80, minWidth: 80,
}, },
{
field: "status",
headerName: "Status",
width: 124,
editable: true,
renderCell: function render({ row }) {
return <MonitoringStatus key="MonStatus1" objId={row.id} status={row.status}
onChange={ (value) => {
mutate({
resource: dataProvider,
id: row.id,
values: {
status: value,
},
});
}}
/>;
},
},
{ {
field: "actions", field: "actions",
headerName: "Actions", headerName: "Actions",
@@ -145,3 +165,21 @@ export const MonitoringList = () => {
</List> </List>
); );
}; };
// {
// field: "monstate",
// headerName: t("orders.fields.status"),
// width: 124,
// renderCell: function render({ row }) {
// return <MonitoringStatus status={row.monstate} />;
// },
// },
// renderEditCell: function render({ row }) {
// return <MonitoringStatusEditChip value={row.status} />;
// },

View File

@@ -1,3 +1,4 @@
import { MonitoringStatus } from "./status/monitoringstatus.types";
export interface IMonitoring { export interface IMonitoring {
@@ -8,5 +9,8 @@ export interface IMonitoring {
sampleperiod: number; sampleperiod: number;
downtime: number; downtime: number;
owner: string; owner: string;
status: "off" | "started" | "stopped";//MonitoringStatus;
} }
//string;

View File

@@ -0,0 +1,450 @@
import { useTranslate, useUpdate } from "@refinedev/core";
import Chip from "@mui/material/Chip";
import type { ChipProps } from "@mui/material/Chip";
import CancelIcon from "@mui/icons-material/Cancel";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import WatchLaterIcon from "@mui/icons-material/WatchLater";
import HighlightOffOutlinedIcon from '@mui/icons-material/HighlightOffOutlined';
import PlayCircleFilledWhiteOutlinedIcon from '@mui/icons-material/PlayCircleFilledWhiteOutlined';
import StopIcon from '@mui/icons-material/Stop';
import NotificationsIcon from "@mui/icons-material/Notifications";
import MopedIcon from "@mui/icons-material/Moped";
import { useTheme } from "@mui/material/styles";
import { red, orange, cyan, blue, green, grey } from "@mui/material/colors";
import { ForkLeft, PersonAdd } from "@mui/icons-material";
import { useState } from "react";
import MenuList from "@mui/material/MenuList";
import MenuItem from "@mui/material/MenuItem";
import ListItemIcon from "@mui/material/ListItemIcon";
import ListItemText from "@mui/material/ListItemText";
import Menu from "@mui/material/Menu";
import { ReactJSXElement } from "@emotion/react/types/jsx-namespace";
type MonitoringStatusProps = {
objId: string;
//dataProviderName: string;
onChange: (value: string ) => void;
status: "off" | "started" | "stopped";
};
// type MonitoringStatusProps = {
// status?: "off" | "started" | "stopped";
// };
//export const MonitoringStatus = ({ objId, dataProviderName, status }: MonitoringStatusProps) => {
export const MonitoringStatus = ({ objId, status , onChange}: MonitoringStatusProps) => {
const t = useTranslate();
const { palette } = useTheme();
const isDarkMode = palette.mode === "dark";
const { mutate } = useUpdate();
const dataProviderName = "monitoringstatus";
//const [showMenuState,setMenuState] = useState<boolean>(true);
let color = "";
let icon: ChipProps["icon"];
const CMDSTART: string = "/start";
const CMDSTOP: string = "/stop";
const CMDOFF: string = "/off";
const STARTED = "started";
const STOPPED = "stopped";
const OFF = "off";
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl); // is for handling the menu for a icon button https://mui.com/material-ui/react-menu/
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const handleStartClick = () => {
// set the statzs Property with the new value
setAnchorEl(null);
onChange('started');
// mutate({
// resource: dataProviderName,
// id: objId,
// values: {
// status: "started",
// },
// });
};
const handleStopClick = () => {
// set the statzs Property with the new value
setAnchorEl(null);
onChange('stopped');
// mutate({
// resource: dataProviderName,
// id: objId,
// values: {
// status: "stopped",
// },
// });
};
const handleOffClick = () => {
// set the statzs Property with the new value
setAnchorEl(null);
onChange('off');
// mutate({
// resource: dataProviderName,
// id: objId,
// values: {
// status: "off",
// },
// });
};
// const handleMenuClick = (evenbr: React.MouseEventHandler<HTMLLIElement>, newstatus: string) => {
// // set the statzs Property with the new value
// setAnchorEl(null);
// mutate({
// resource: {dataProviderName}+"/setStatus",
// id,
// values: {
// status: {newstatus},
// },
// });
// };
const showMenu = (status: string, compare: string) : boolean => {
if (status === compare) {
return false;
}
return true;
}
switch (status) {
case "off":
color = isDarkMode ? grey[200] : grey[800];
icon = (
<HighlightOffOutlinedIcon
sx={{
fill: isDarkMode ? grey[200] : grey[600],
}}
/>
);
break;
case "started":
color = isDarkMode ? green[200] : green[800];
icon = (
<PlayCircleFilledWhiteOutlinedIcon
sx={{
fill: isDarkMode ? green[200] : green[600],
}}
/>
);
break;
case "stopped":
color = isDarkMode ? red[200] : red[800];
icon = (
<StopIcon
sx={{
fill: isDarkMode ? red[200] : red[600],
}}
/>
);
break;
}
const getMonMenu = () : JSX.Element[] => {
let monMenu: JSX.Element[] = []
if (showMenu(status, STARTED)) {
monMenu.push(<MenuItem key={1} id="chip-menu-Item-1" onClick={handleStartClick}>
<ListItemIcon>
<PlayCircleFilledWhiteOutlinedIcon
sx={{
fill: isDarkMode ? green[200] : green[600],
}}
/>
</ListItemIcon>
Start
</MenuItem>)
}
if (showMenu(status, STOPPED)) {
monMenu.push(<MenuItem key={2} id="chip-menu-Item-2" onClick={handleStopClick}>
<ListItemIcon>
<StopIcon
sx={{
fill: isDarkMode ? red[200] : red[600],
}}
/>
</ListItemIcon>
Stop
</MenuItem>)
}
if (showMenu(status, OFF)) {
monMenu.push(<MenuItem key={3} id="chip-menu-Item-3" onClick={handleOffClick}>
<ListItemIcon>
<HighlightOffOutlinedIcon
sx={{
fill: isDarkMode ? grey[200] : grey[600],
}}
/>
</ListItemIcon>
Deactivate
</MenuItem>)
}
return monMenu;
}
// let chipMenu = null;
// if(showMenuState === true) {
// //show the menu
// chipMenu = () => {
// return (
// <div>
// <MenuList>
// <MenuItem>
// <ListItemIcon>
// </ListItemIcon>
// <ListItemText>Start</ListItemText>
// </MenuItem>
// </MenuList>
// </div>
// );
// }
// }
return (
<div>
<Chip
key="MonChip"
id="MonChip1"
variant="outlined"
size="medium"
icon={icon}
sx={{
borderColor: color,
color: color,
width:100,
alignItems: "center",
justifyContent: "left",
}}
label={status}
onClick={handleClick}
/>
<Menu
anchorEl={anchorEl}
key="monchip-menu"
id="monStatus-menu"
open={open}
onClose={handleClose}
onClick={handleClose}
>
{getMonMenu()}
</Menu>
</div>
);
};
//
// { showMenuState ?
// (
// <div>
// <Menu
// anchorEl={anchorEl}
// id="account-menu"
// open={open}
// onClose={handleClose}
// onClick={handleClose}
// >
// <MenuItem onClick={handleClose}>
// <ListItemIcon>
// <HighlightOffOutlinedIcon
// sx={{
// fill: isDarkMode ? grey[200] : grey[600],
// }}
// />
// </ListItemIcon>
// Start
// </MenuItem>
// </Menu>
// </div>
// )
// : null
// }
// PaperProps={{
// elevation: 0,
// sx: {
// overflow: 'visible',
// filter: 'drop-shadow(0px 2px 8px rgba(0,0,0,0.32))',
// mt: 1.5,
// '& .MuiAvatar-root': {
// width: 32,
// height: 32,
// ml: -0.5,
// mr: 1,
// },
// '&::before': {
// content: '""',
// display: 'block',
// position: 'absolute',s
// top: 0,
// right: 14,
// width: 10,
// height: 10,
// bgcolor: 'background.paper',
// transform: 'translateY(-50%) rotate(45deg)',
// zIndex: 0,
// },
// },
// }
// }
// <div>
// <MenuList>
// <MenuItem>
// <ListItemIcon>
// </ListItemIcon>
// <ListItemText>Start</ListItemText>
// </MenuItem>
// </MenuList>
// </div>
// <>
// <Tooltip title="More">
// <IconButton aria-label="more" onClick={onClick} size="small" data-testid="more">
// <MoreHorizIcon fontSize="small" />
// </IconButton>
// </Tooltip>
// {state.contextMenuAnchorElement ? (
// <ProjectContextMenu
// menuAnchor={state.contextMenuAnchorElement}
// project={project}
// onChange={onChange}
// onClose={onCloseContextMenu}
// />
// ) : null}
// </>
// label={t(`enum.orderStatuses.${status}`)}
// case "Delivered":
// color = isDarkMode ? green[200] : green[800];
// icon = (
// <CheckCircleIcon
// sx={{
// fill: isDarkMode ? green[200] : green[600],
// }}
// />
// );mutate
// break;
// case "Cancelled":
// color = isDarkMode ? red[200] : red[800];
// icon = (
// <CancelIcon
// sx={{
// fill: isDarkMode ? red[200] : red[600],
// }}
// />s
// );
// break;
// ---------------------------------
// { showMenu(status, STARTED) ?
// [
// <>
// <MenuItem onClick={handleClose}>
// <ListItemIcon>
// <PlayCircleFilledWhiteOutlinedIcon
// sx={{
// fill: isDarkMode ? green[200] : green[600],
// }}
// />
// </ListItemIcon>
// Start
// </MenuItem>
// </>
// ]
// : []
// }
// { showMenu(status, STOPPED) ?
// [
// <>
// <MenuItem onClick={handleClose}>
// <ListItemIcon>
// <StopIcon
// sx={{
// fill: isDarkMode ? red[200] : red[600],
// }}
// />
// </ListItemIcon>
// Stop
// </MenuItem>
// </>
// ]
// : []
// }
// { showMenu(status, OFF) ?
// <>
// <MenuItem onClick={handleClose}>
// <ListItemIcon>
// <HighlightOffOutlinedIcon
// sx={{
// fill: isDarkMode ? grey[200] : grey[600],
// }}
// />
// </ListItemIcon>
// Deactivate
// </MenuItem>
// </>
// : null
// }

View File

@@ -0,0 +1,12 @@
export type MonitoringStatus = {
monstate: "off" | "started" | "stopped";
};
export type MonitoringStatusProps = {
id: string;
dataProviderName: string;
status: string;
};

View File

@@ -0,0 +1,10 @@
export type MonitoringStatusEditProps = {
value: string;
onChange?: (e: React.SyntheticEvent<Element>, value: string | null) => void;
};

View File

@@ -0,0 +1,76 @@
import { useTranslate } from "@refinedev/core";
import Chip from "@mui/material/Chip";
import type { ChipProps } from "@mui/material/Chip";
import HighlightOffOutlinedIcon from '@mui/icons-material/HighlightOffOutlined';
import PlayCircleFilledWhiteOutlinedIcon from '@mui/icons-material/PlayCircleFilledWhiteOutlined';
import StopIcon from '@mui/icons-material/Stop';
import { useTheme } from "@mui/material/styles";
import { red, orange, cyan, blue, green, grey } from "@mui/material/colors";
import { MonitoringStatusChipProps } from "./monitoringstatuschip.types";
export const MonitoringStatusChip = ({ value }: MonitoringStatusChipProps) => {
const t = useTranslate();
const { palette } = useTheme();
const isDarkMode = palette.mode === "dark";
let color = "";
let icon: ChipProps["icon"];
switch (value) {
case "off":
color = isDarkMode ? grey[200] : grey[800];
icon = (
<HighlightOffOutlinedIcon
sx={{
fill: isDarkMode ? grey[200] : grey[600],
}}
/>
);
break;
case "started":
color = isDarkMode ? green[200] : green[800];
icon = (
<PlayCircleFilledWhiteOutlinedIcon
sx={{
fill: isDarkMode ? green[200] : green[600],
}}
/>
);
break;
case "stopped":
color = isDarkMode ? red[200] : red[800];
icon = (
<StopIcon
sx={{
fill: isDarkMode ? red[200] : red[600],
}}
/>
);
break;
}
return (
<div>
<Chip
variant="outlined"
size="medium"
icon={icon}
sx={{
borderColor: color,
color: color,
width:100,
alignItems: "center",
justifyContent: "left",
}}
label={value}
/>
</div>
);
};

View File

@@ -0,0 +1,10 @@
export type MonitoringStatusChipProps = {
value?: string;
};

View File

@@ -0,0 +1,95 @@
import * as React from "react";
import Autocomplete from "@mui/material/Autocomplete";
import TextField from "@mui/material/TextField";
import Stack from "@mui/material/Stack";
import { MonitoringStatusEditProps } from "./monitoringstatusEdit.types";
import { MonitoringStatusChip } from "./monitoringstatuschip";
export const MonitoringStatusEditChip = ({ value, onChange }: MonitoringStatusEditProps) => {
const [val, setVal] = React.useState({value});
const [receivers, setReceivers] = React.useState([]);
// const handleClick = () => {
// setVal(top100Films[0]); //you pass any value from the array of top100Films
// // set value in TextField from dropdown list
// };
return (
<Stack spacing={1} sx={{ width: 500 }}>
<Autocomplete
id="MonitoringStatusChip"
limitTags={1}
options={chipSetting.map((option) => option.value)}
defaultValue={value}
onChange={onChange}
renderOption={() => (
<MonitoringStatusChip
value = {value}
/>
)}
renderInput={(params) => (
<MonitoringStatusChip
value = {value}
/>
)}
/>
</Stack>
);
}
// -------------renderinpurt ori
{/* <TextField
{...params}
variant="filled"
label="freeSolo"
placeholder="Favorites"
/> */}
// renderTags={(value, getTagProps) =>
// value.map((option, index) => (
// <MonitoringStatusChip
// value = {chipSetting[index].value}
// {...getTagProps({ index })}
// />
// ))
// }
// renderTags={(value, getTagProps) =>
// value.map((option, index) => (
// <Chip
// variant="outlined"
// label={option}
// {...getTagProps({ index })}
// />
// ))
// }
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
// const top100Films = [
// { title: "The Shawshank Redemption", year: 1994 },
// { title: "The Godfather", year: 1972 },
// { title: "The Godfather: Part II", year: 1974 },
// { title: "The Dark Knight", year: 2008 },
// { title: "12 Angry Men", year: 1957 },
// { title: "Schindler's List", year: 1993 },
// { title: "Pulp Fiction", year: 1994 },
// ];
const chipSetting = [
{ value: "off" },
{ value: "started"},
{ value: "stopped"},
];

View File

@@ -0,0 +1,165 @@
import * as React from "react";
import Autocomplete from "@mui/material/Autocomplete";
import TextField from "@mui/material/TextField";
import Stack from "@mui/material/Stack";
import { MonitoringStatusEditProps } from "./monitoringstatusEdit.types";
import { MonitoringStatusChip } from "./monitoringstatuschip";
import useTheme from "@mui/material/styles/useTheme";
import { red, orange, cyan, blue, green, grey } from "@mui/material/colors";
import HighlightOffOutlinedIcon from '@mui/icons-material/HighlightOffOutlined';
import PlayCircleFilledWhiteOutlinedIcon from '@mui/icons-material/PlayCircleFilledWhiteOutlined';
import StopIcon from '@mui/icons-material/Stop';
import Box from "@mui/material/Box";
export const MonitoringStatusEditChip = ({ value, onChange }: MonitoringStatusEditProps) => {
const [val, setVal] = React.useState({value});
const [receivers, setReceivers] = React.useState([]);
const { palette } = useTheme();
const isDarkMode = palette.mode === "dark";
let color = "";
// <TextField
// id="input-with-icon-textfield"
// label="TextField"
// InputProps={{
// startAdornment: (
// <InputAdornment position="start">
// <AccountCircle />
// </InputAdornment>
// ),
// }}
const getIcon = (value:string) => {
switch (value) {
case "off":
return (
<HighlightOffOutlinedIcon
sx={{fill: isDarkMode ? grey[200] : grey[600],}}
/>
)
case "started":
return (
<HighlightOffOutlinedIcon
sx={{fill: isDarkMode ? grey[200] : grey[600],}}
/>
)
case "stopped":
return (
<HighlightOffOutlinedIcon
sx={{fill: isDarkMode ? grey[200] : grey[600],}}
/>
)
}
return (
<HighlightOffOutlinedIcon
sx={{fill: isDarkMode ? grey[200] : grey[600],}}
/>)
}
// renderOption={(props, option) => (
// <Box component="li" sx={{ '& > img': { mr: 2, flexShrink: 0 } }} {...props}>
// <img
// loading="lazy"
// width="20"
// srcSet={`https://flagcdn.com/w40/${option.code.toLowerCase()}.png 2x`}
// src={`https://flagcdn.com/w20/${option.code.toLowerCase()}.png`}
// alt=""
// />
// {option.label} ({option.code}) +{option.phone}
// </Box>
// )}
// const handleClick = () => {
// setVal(top100Films[0]); //you pass any value from the array of top100Films
// // set value in TextField from dropdown list
// };
return (
<Stack spacing={1} sx={{ width: 500 }}>
<Autocomplete
id="MonitoringStatusChip"
limitTags={1}
options={chipSetting.map((option) => option.value)}
defaultValue={value}
onChange={onChange}
renderOption={(props, option) => (
<Box component="li" sx={{ '& > img': { mr: 2, flexShrink: 0 } }} {...props}>
{getIcon(value)}
{option}
</Box>
)}
renderInput={(params) => (
<>
<TextField
{...params}
variant="filled"
label={value}
/>
</>
)}
/>
</Stack>
);
}
// -------------renderinpurt ori
// renderTags={(value, getTagProps) =>
// value.map((option, index) => (
// <MonitoringStatusChip
// value = {chipSetting[index].value}
// {...getTagProps({ index })}
// />
// ))
// }
// renderTags={(value, getTagProps) =>
// value.map((option, index) => (
// <Chip
// variant="outlined"
// label={option}
// {...getTagProps({ index })}
// />
// ))
// }
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
// const top100Films = [
// { title: "The Shawshank Redemption", year: 1994 },
// { title: "The Godfather", year: 1972 },
// { title: "The Godfather: Part II", year: 1974 },
// { title: "The Dark Knight", year: 2008 },
// { title: "12 Angry Men", year: 1957 },
// { title: "Schindler's List", year: 1993 },
// { title: "Pulp Fiction", year: 1994 },
// ];
const chipSetting = [
{ value: "off" },
{ value: "started"},
{ value: "stopped"},
];

View File

@@ -0,0 +1,177 @@
import * as React from "react";
import Chip from "@mui/material/Chip";
import Autocomplete from "@mui/material/Autocomplete";
import TextField from "@mui/material/TextField";
import Stack from "@mui/material/Stack";
export default function Tags() {
const [val, setVal] = React.useState({});
const [receivers, setReceivers] = React.useState([]);
console.log(receivers);
const handleClick = () => {
setVal(top100Films[0]); //you pass any value from the array of top100Films
// set value in TextField from dropdown list
};
return (
<Stack spacing={1} sx={{ width: 500 }}>
<Autocomplete
multiple
id="tags-filled"
options={top100Films.map((option) => option.title)}
defaultValue={[top100Films[13].title]}
freeSolo
onChange={(e, value, situation, option) => {
if (situation === "removeOption") {
console.log("--->", e, value, situation, option);
}
setReceivers((state) => value);
}}
renderTags={(value, getTagProps) =>
value.map((option, index) => (
<Chip
variant="outlined"
label={option}
{...getTagProps({ index })}
/>
))
}
renderInput={(params) => (
<TextField
{...params}
variant="filled"
label="freeSolo"
placeholder="Favorites"
/>
)}
/>
</Stack>
);
}
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ title: "The Shawshank Redemption", year: 1994 },
{ title: "The Godfather", year: 1972 },
{ title: "The Godfather: Part II", year: 1974 },
{ title: "The Dark Knight", year: 2008 },
{ title: "12 Angry Men", year: 1957 },
{ title: "Schindler's List", year: 1993 },
{ title: "Pulp Fiction", year: 1994 },
{
title: "The Lord of the Rings: The Return of the King",
year: 2003
},
{ title: "The Good, the Bad and the Ugly", year: 1966 },
{ title: "Fight Club", year: 1999 },
{
title: "The Lord of the Rings: The Fellowship of the Ring",
year: 2001
},
{
title: "Star Wars: Episode V - The Empire Strikes Back",
year: 1980
},
{ title: "Forrest Gump", year: 1994 },
{ title: "Inception", year: 2010 },
{
title: "The Lord of the Rings: The Two Towers",
year: 2002
},
{ title: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ title: "Goodfellas", year: 1990 },
{ title: "The Matrix", year: 1999 },
{ title: "Seven Samurai", year: 1954 },
{
title: "Star Wars: Episode IV - A New Hope",
year: 1977
},
{ title: "City of God", year: 2002 },
{ title: "Se7en", year: 1995 },
{ title: "The Silence of the Lambs", year: 1991 },
{ title: "It's a Wonderful Life", year: 1946 },
{ title: "Life Is Beautiful", year: 1997 },
{ title: "The Usual Suspects", year: 1995 },
{ title: "Léon: The Professional", year: 1994 },
{ title: "Spirited Away", year: 2001 },
{ title: "Saving Private Ryan", year: 1998 },
{ title: "Once Upon a Time in the West", year: 1968 },
{ title: "American History X", year: 1998 },
{ title: "Interstellar", year: 2014 },
{ title: "Casablanca", year: 1942 },
{ title: "City Lights", year: 1931 },
{ title: "Psycho", year: 1960 },
{ title: "The Green Mile", year: 1999 },
{ title: "The Intouchables", year: 2011 },
{ title: "Modern Times", year: 1936 },
{ title: "Raiders of the Lost Ark", year: 1981 },
{ title: "Rear Window", year: 1954 },
{ title: "The Pianist", year: 2002 },
{ title: "The Departed", year: 2006 },
{ title: "Terminator 2: Judgment Day", year: 1991 },
{ title: "Back to the Future", year: 1985 },
{ title: "Whiplash", year: 2014 },
{ title: "Gladiator", year: 2000 },
{ title: "Memento", year: 2000 },
{ title: "The Prestige", year: 2006 },
{ title: "The Lion King", year: 1994 },
{ title: "Apocalypse Now", year: 1979 },
{ title: "Alien", year: 1979 },
{ title: "Sunset Boulevard", year: 1950 },
{
title:
"Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb",
year: 1964
},
{ title: "The Great Dictator", year: 1940 },
{ title: "Cinema Paradiso", year: 1988 },
{ title: "The Lives of Others", year: 2006 },
{ title: "Grave of the Fireflies", year: 1988 },
{ title: "Paths of Glory", year: 1957 },
{ title: "Django Unchained", year: 2012 },
{ title: "The Shining", year: 1980 },
{ title: "WALL·E", year: 2008 },
{ title: "American Beauty", year: 1999 },
{ title: "The Dark Knight Rises", year: 2012 },
{ title: "Princess Mononoke", year: 1997 },
{ title: "Aliens", year: 1986 },
{ title: "Oldboy", year: 2003 },
{ title: "Once Upon a Time in America", year: 1984 },
{ title: "Witness for the Prosecution", year: 1957 },
{ title: "Das Boot", year: 1981 },
{ title: "Citizen Kane", year: 1941 },
{ title: "North by Northwest", year: 1959 },
{ title: "Vertigo", year: 1958 },
{
title: "Star Wars: Episode VI - Return of the Jedi",
year: 1983
},
{ title: "Reservoir Dogs", year: 1992 },
{ title: "Braveheart", year: 1995 },
{ title: "M", year: 1931 },
{ title: "Requiem for a Dream", year: 2000 },
{ title: "Amélie", year: 2001 },
{ title: "A Clockwork Orange", year: 1971 },
{ title: "Like Stars on Earth", year: 2007 },
{ title: "Taxi Driver", year: 1976 },
{ title: "Lawrence of Arabia", year: 1962 },
{ title: "Double Indemnity", year: 1944 },
{
title: "Eternal Sunshine of the Spotless Mind",
year: 2004
},
{ title: "Amadeus", year: 1984 },
{ title: "To Kill a Mockingbird", year: 1962 },
{ title: "Toy Story 3", year: 2010 },
{ title: "Logan", year: 2017 },
{ title: "Full Metal Jacket", year: 1987 },
{ title: "Dangal", year: 2016 },
{ title: "The Sting", year: 1973 },
{ title: "2001: A Space Odyssey", year: 1968 },
{ title: "Singin' in the Rain", year: 1952 },
{ title: "Toy Story", year: 1995 },
{ title: "Bicycle Thieves", year: 1948 },
{ title: "The Kid", year: 1921 },
{ title: "Inglourious Basterds", year: 2009 },
{ title: "Snatch", year: 2000 },
{ title: "3 Idiots", year: 2009 },
{ title: "Monty Python and the Holy Grail", year: 1975 }
];

1
vrpmdvserver/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/vrpmwvpy-save-2023-03-27.zip

71
vrpmdvserver/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,71 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
},
"cmake.sourceDirectory": "/home/markus/git/vrpmdvweb/vrpmdvserver/rt_service"
}

View File

@@ -3,3 +3,4 @@
/vrpmdvmonitoringschema.cpython-310.pyc /vrpmdvmonitoringschema.cpython-310.pyc
/vrpmdvmonreq.cpython-310.pyc /vrpmdvmonreq.cpython-310.pyc
/vrpmdvmonreqschema.cpython-310.pyc /vrpmdvmonreqschema.cpython-310.pyc
/vrpmdvmonitoringState.cpython-310.pyc

8
vrpmdvserver/build/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
/.cmake/
/CMakeFiles/
/.ninja_deps
/.ninja_log
/build.ninja
/cmake_install.cmake
/CMakeCache.txt
/compile_commands.json

File diff suppressed because one or more lines are too long

BIN
vrpmdvserver/build/rt_service.so Executable file

Binary file not shown.

1
vrpmdvserver/extensions/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/__pycache__/

View File

View File

@@ -0,0 +1 @@
/__pycache__/

Binary file not shown.

View File

@@ -1 +1 @@
[{"id": "a214da99-2a77-4229-905b-5137a0d8071c", "created_at": "03/20/2024, 08:12", "name": "Monitorings1", "samplerate": 3750, "sampleperiod": 10, "downtime": 40, "owner": "Markus Lehr"}] [{"id": "7c7a3fd8-0951-491c-bcf2-dc917058f60e", "created_at": "03/31/2024, 13:39", "name": "MM56", "samplerate": 3000, "sampleperiod": 2, "downtime": 7, "owner": "ML1", "status": "off"}, {"id": "4c17fd91-e273-4c1b-8561-5d2506c0f8b0", "created_at": "03/31/2024, 13:39", "name": "MM2", "samplerate": 7000, "sampleperiod": 1, "downtime": 5, "owner": "ML1", "status": "off"}, {"id": "13277d6a-4654-4448-8162-c057e8e03eac", "created_at": "03/31/2024, 13:48", "name": "MM1", "samplerate": 10000, "sampleperiod": 1, "downtime": 0, "owner": "ML1", "status": "stopped"}, {"id": "a412c952-cff7-4a4d-a064-214f4edbaac8", "created_at": "03/31/2024, 13:48", "name": "MM30", "samplerate": 3000, "sampleperiod": 2, "downtime": 30, "owner": "ML3", "status": "started"}, {"id": "a0d2fe83-f507-41c6-a833-283cf3ad69cf", "created_at": "03/31/2024, 13:48", "name": "MM37", "samplerate": 3000, "sampleperiod": 2, "downtime": 4, "owner": "ML35", "status": "started"}]

View File

@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.5)
# Find python and Boost - both are required dependencies
find_package(PythonLibs 3.10 REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
#set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)
# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(rt_service MODULE rt_service.cpp)
# Set up the libraries and header search paths for this target
target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS})
set(MY_RESOURCE_FILE rt_service.so)
#set_directory_properties(MY_EXTENSION_LIB /home/markus/git/vrpmwvweb/vrpmdvserver/extensions/)
#file(COPY ${CMAKE_CURRENT_BINARY_DIR}/${MY_RESOURCE_FILE}
# DESTINATION /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)
# location of the Python header files
#PYTHON_VERSION = 3.10
#PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
#BOOST_INC = /usr/include
#BOOST_LIB = /usr/lib
# compile mesh classes
#TARGET = rt_service
#$(TARGET).so: $(TARGET).o g++ -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -lboost_python-$(PYTHON_VERSION) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so
#$(TARGET).o: $(TARGET).cpp g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

View File

@@ -0,0 +1,69 @@
#include <boost/python.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
#include <string>
//#include <sstream>
//#include <vector>
struct RTService
{
// private:
// /* data */
// public:
// RT_Service(/* args */) {}
// ~RT_Service() {}
bool createMonitoring(std::string id) {
//TODO ML: add this to the M4Core
return true;
}
bool deleteMonitoring(std::string id) {
//TODO ML: add this to the M4Core
return true;
}
std::string getMonitoringState(std::string id) {
//TODO ask the M4Core for the Monitpring Status
return "Start";
}
boost::python::list getMonitoringStates() {
//TODO ask the M4Core for the Monitpring Status
boost::python::list list;
return list;
}
bool setMonitoringStatus(std::string id, std::string status) {
//set the Status
return true;
}
};
using namespace boost::python;
BOOST_PYTHON_MODULE(rt_service)
{
class_<RTService>("RT_Service")
.def("createMonitoring", &RTService::createMonitoring)
.def("getMonitoringStatus", &RTService::getMonitoringState)
.def("getAllMonitoringStat", &RTService::getMonitoringStates)
.def("setMonitoringStatus", &RTService::setMonitoringStatus)
;
};
//examples
// long l = len(msgs);
// std::stringstream ss;
// for (long i = 0; i<l; ++i) {
// if (i>0) ss << ", ";
// std::string s = boost::python::extract<std::string>(msgs[i]);
// ss << s;
// }
// mMsg = ss.str();

View File

@@ -2,6 +2,7 @@ from uuid import uuid4
import uuid import uuid
from flask import jsonify from flask import jsonify
import json import json
from extensions.rt_service import rt_service as rts
# from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema # from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
# from vrpmdvmonitoring import VRPMDV_Monitoring # from vrpmdvmonitoring import VRPMDV_Monitoring
@@ -13,8 +14,9 @@ class VRPMDV_Data:
def __init__(self): def __init__(self):
#self.loaded = False #self.loaded = False
self.mons = [] self.mons:list = []
self.loaded = self.loadFile() self.loaded = self.loadFile()
self.rtservice = rts.RT_Service()
def loadFile(self): def loadFile(self):
try: try:
@@ -27,11 +29,11 @@ class VRPMDV_Data:
else: else:
# data = json.loads(fmons) # data = json.loads(fmons)
schema = VRPMDV_MonitoringSchema(many=True) schema = VRPMDV_MonitoringSchema(many=True)
res = schema.loads(fmons) # data #res = schema.loads(fmons) # data
self.mons = schema.loads(fmons) # .append(res) self.mons = schema.loads(fmons) # .append(res)
return True return True
except: except:
#nothing todo #nothing todo ML we should create a file later the database
print("file not found") print("file not found")
def saveFile(self): def saveFile(self):
@@ -50,8 +52,8 @@ class VRPMDV_Data:
def getMonitorings(self): def getMonitorings(self):
# 1st time read file # 1st time read file
if not self.loaded : # if not self.loaded :
self.loaded = self.loadFile() # self.loaded = self.loadFile()
schema = VRPMDV_MonitoringSchema() schema = VRPMDV_MonitoringSchema()
result = schema.dumps(self.mons, many=True) result = schema.dumps(self.mons, many=True)
@@ -67,32 +69,51 @@ class VRPMDV_Data:
schema = VRPMDV_MonitoringSchema() schema = VRPMDV_MonitoringSchema()
return schema.dumps(matched_obj) return schema.dumps(matched_obj)
def setMonitoring(self, vrpmid, request): def setMonitoring(self, id, request):
try: try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid) matched_obj = next(x for x in self.mons if str(x.id) == id)
matched_obj.name = request.name
matched_obj.samplerate = request.samplerate
matched_obj.sampleperiod = request.sampleperiod
matched_obj.downtime = request.downtime
self.saveFile()
except: except:
return "no Item found" return "no Item found"
if 'name' in request : matched_obj.name = request['name']
if 'samplerate' in request : matched_obj.samplerate = request['samplerate']
if 'sampleperiod' in request : matched_obj.sampleperiod = request['sampleperiod']
if 'downtime' in request : matched_obj.downtime = request['downtime']
if 'status' in request : matched_obj.setStatus(request['status'])
self.saveFile()
# we find it and we return it # we find it and we return it
schema = VRPMDV_MonitoringSchema() schema = VRPMDV_MonitoringSchema()
return schema.dumps(matched_obj) return schema.dumps(matched_obj)
# try:
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
# matched_obj.name = request.name
# matched_obj.samplerate = request.samplerate
# matched_obj.sampleperiod = request.sampleperiod
# matched_obj.downtime = request.downtime
# self.saveFile()
# except:
# return "no Item found"
# # we find it and we return it
# schema = VRPMDV_MonitoringSchema()
# return schema.dumps(matched_obj)
def createMonitoring(self, request): def createMonitoring(self, request):
#mon = VRPMDV_Monitoring(request["name"], request["samplerate"], request["sampleperiod"], request["downtime"], request["owner"]) #mon = VRPMDV_Monitoring(request["name"], request["samplerate"], request["sampleperiod"], request["downtime"], request["owner"])
id = uuid.uuid4() id = uuid.uuid4()
mon = VRPMDV_Monitoring(id, request.name, request.samplerate, request.sampleperiod, request.downtime, request.owner) mon = VRPMDV_Monitoring(id, request.name, request.samplerate, request.sampleperiod, request.downtime, request.status, request.owner)
iscreated = mon.createMonitoring()
#iscreated = self.rtservice.createMonitoring(str(id))
if not self.loaded : # if not self.loaded :
self.loaded = self.loadFile() # self.loaded = self.loadFile()
# create monitoring # create monitoring
self.mons.append(mon) self.mons.append(mon)
#save to file #save to file
@@ -102,8 +123,8 @@ class VRPMDV_Data:
return schema.dumps(mon) return schema.dumps(mon)
def deleteMonitoring(self, vrpmid): def deleteMonitoring(self, vrpmid):
if not self.loaded : # if not self.loaded :
self.loaded = self.loadFile() # self.loaded = self.loadFile()
# find monitoring with uuid # find monitoring with uuid
#result = filter(lambda mon: str(mon.uuid) == vrpmid["uuid"], self.mons) #result = filter(lambda mon: str(mon.uuid) == vrpmid["uuid"], self.mons)
@@ -112,7 +133,9 @@ class VRPMDV_Data:
except: except:
return "no Item found" return "no Item found"
# we find it and now remove from list
# we find it, delete on realtime side and now remove from list
matched_obj.deleteMonitoring()
self.mons.remove(matched_obj) self.mons.remove(matched_obj)
#save the list #save the list
self.saveFile() self.saveFile()
@@ -122,18 +145,47 @@ class VRPMDV_Data:
def startMonitoring(self, vrpmid): def startMonitoring(self, vrpmid):
#if not self.loaded : # if not self.loaded :
# self.loaded = self.loadFile() # self.loaded = self.loadFile()
#call the start API of the kernel treiber
#call the start API of the c++ driver
try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
except:
return "no Item found"
return "started" if matched_obj.startMonitoring() :
#TODO ML return the state
return "started"
return "created"
def stopMonitoring(self, vrpmid): def stopMonitoring(self, vrpmid):
#if not self.loaded : # if not self.loaded :
# self.loaded = self.loadFile() # self.loaded = self.loadFile()
#call the start API of the kernel treiber
return "stopped"
#call the start API of the c++ driver
try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
except:
return "no Item found"
matched_obj.startMonitoring()
return matched_obj.monstate.name
def setStatus(self, id, vrpmStatus):
if 'status' in vrpmStatus :
matched_obj = self.findMonitoring(id)
#call the start API of the c++ driver
matched_obj.setStatus(vrpmStatus['status'])
return matched_obj.status
return ""
def findMonitoring(self, id):
try:
return next(x for x in self.mons if str(x.id) == id)
except:
return "no Item found"

View File

@@ -3,7 +3,8 @@ import datetime as dt
from marshmallow import Schema, fields, post_load from marshmallow import Schema, fields, post_load
from vrpmdvmonreq import VRPMDV_MonReq from vrpmdvmonreq import VRPMDV_MonReq
from extensions.rt_service import rt_service as rts
from vrpmdvmonitoringState import VRPMDVMonitoringState
# class VRPMDV_MonReq: # class VRPMDV_MonReq:
# def __init__(self, name , samplerate, sampleperiod, downtime, owner) : # def __init__(self, name , samplerate, sampleperiod, downtime, owner) :
@@ -14,7 +15,45 @@ from vrpmdvmonreq import VRPMDV_MonReq
# self.owner = owner # self.owner = owner
class VRPMDV_Monitoring(VRPMDV_MonReq): class VRPMDV_Monitoring(VRPMDV_MonReq):
def __init__(self, id, name , samplerate, sampleperiod, downtime, owner="None", created_at=dt.datetime.now()) :
def __init__(self, id, name , samplerate, sampleperiod, downtime, status, owner="None", created_at=dt.datetime.now()) :
self.id = id self.id = id
self.created_at = created_at self.created_at = created_at
super().__init__(name, samplerate, sampleperiod, downtime, owner) self.rtservice = rts.RT_Service()
super().__init__(name, samplerate, sampleperiod, downtime, owner, status)
def createMonitoring(self) :
if self.status != VRPMDVMonitoringState.OFF:
iscreated = self.rtservice.createMonitoring(str(self.id))
if not iscreated :
self.status = VRPMDVMonitoringState.OFF
return True
return False
def deleteMonitoring(self) :
isdeleted = self.rtservice.deleteMonitoring(str(self.id))
if (isdeleted) :
self.monstate = VRPMDVMonitoringState.OFF
return True
return False
def startMonitoring(self) :
isstarted = self.rtservice.setMonitoringState(str(self.id), VRPMDVMonitoringState.started)
if (isstarted) :
self.monstate = VRPMDVMonitoringState.STARTED
return True
return False
def stopMonitoring(self) :
isstopped = self.rtservice.setMonitoringState(str(self.id), VRPMDVMonitoringState.stopped)
if (isstopped) :
self.monstate = VRPMDVMonitoringState.STOPPED
return True
return False
def setStatus(self, status) :
isStatusSet = self.rtservice.setMonitoringStatus(str(self.id), status)
if (isStatusSet) :
self.status = status
return True
return False

View File

@@ -0,0 +1,31 @@
#from enum import Enum
from marshmallow import Schema, fields, post_load
class VRPMDVMonitoringState():
OFF = "off"
CREATED = "created"
STARTED = "started"
STOPPED = "stopped"
def __init__(self, state = OFF):
self.state = state
class VRPMDVMonitoringStateSchema(Schema):
monstate = fields.String()
@post_load
def make_vrpmdv_MonitoringState(self, data, **kwargs):
return VRPMDVMonitoringState(**data)
# class VRPMDVMonitoringState(Enum):
# off = 1
# created = 2
# started = 3
# stopped = 4

View File

@@ -2,11 +2,11 @@ import uuid
import datetime as dt import datetime as dt
from marshmallow import Schema, fields, post_load, post_dump from marshmallow import Schema, fields, post_load, post_dump
from vrpmdvmonitoring import VRPMDV_Monitoring from vrpmdvmonitoring import VRPMDV_Monitoring
from vrpmdvmonitoringState import VRPMDVMonitoringStateSchema
class VRPMDV_MonitoringSchema(Schema): class VRPMDV_MonitoringSchema(Schema):
#__envelope__ = {"single": None, "many": "monitorings"}
id = fields.UUID() id = fields.UUID()
created_at = fields.DateTime("%m/%d/%Y, %H:%M") created_at = fields.DateTime("%m/%d/%Y, %H:%M")
name = fields.String() name = fields.String()
@@ -14,6 +14,9 @@ class VRPMDV_MonitoringSchema(Schema):
sampleperiod = fields.Integer() sampleperiod = fields.Integer()
downtime = fields.Integer() downtime = fields.Integer()
owner = fields.String() owner = fields.String()
status = fields.String()
#monstate = fields.Enum(VRPMDVMonitoringState)
# def get_envelope_key(self, many): # def get_envelope_key(self, many):
# """Helper to get the envelope key.""" # """Helper to get the envelope key."""
@@ -28,7 +31,12 @@ class VRPMDV_MonitoringSchema(Schema):
@post_load @post_load
def make_vrpmdv_Monitoring(self, data, **kwargs): def make_vrpmdv_Monitoring(self, data, **kwargs):
return VRPMDV_Monitoring(**data) mon = VRPMDV_Monitoring(**data)
#create the monitoring on the realtime side
mon.createMonitoring()
return mon

View File

@@ -3,11 +3,12 @@ import datetime as dt
class VRPMDV_MonReq: class VRPMDV_MonReq:
def __init__(self, name , samplerate, sampleperiod, downtime, owner) : def __init__(self, name , samplerate, sampleperiod, downtime, owner, status) :
self.name = name self.name = name
self.samplerate = samplerate self.samplerate = samplerate
self.sampleperiod = sampleperiod self.sampleperiod = sampleperiod
self.downtime = downtime self.downtime = downtime
self.owner = owner self.owner = owner
self.status = status

View File

@@ -10,6 +10,7 @@ class VRPMDV_MonReqSchema(Schema):
sampleperiod = fields.Integer() sampleperiod = fields.Integer()
downtime = fields.Integer() downtime = fields.Integer()
owner = fields.String() owner = fields.String()
status = fields.String()
@post_load @post_load
def make_vrpmdv_MonitoringReq(self, data, **kwargs): def make_vrpmdv_MonitoringReq(self, data, **kwargs):

View File

@@ -30,7 +30,8 @@ def get_monitoring(id):
@app.route('/vrpmdvapi/1_0/monitorings/<id>', methods=['PATCH']) @app.route('/vrpmdvapi/1_0/monitorings/<id>', methods=['PATCH'])
def set_monitoring(id): def set_monitoring(id):
vrpmreq = VRPMDV_MonReqSchema().load(request.get_json()) # vrpmreq = VRPMDV_MonReqSchema().load(request.get_json())
vrpmreq = request.get_json()
data = vrpmdvdata.setMonitoring(id, vrpmreq) data = vrpmdvdata.setMonitoring(id, vrpmreq)
resp = Response(data, status=200, mimetype='application/json') resp = Response(data, status=200, mimetype='application/json')
return resp return resp
@@ -52,20 +53,27 @@ def delete_monitoring(id):
@app.route('/vrpmdvapi/1_0/monitorings/start', methods=['PUT']) @app.route('/vrpmdvapi/1_0/monitorings/start', methods=['PATCH'])
def start_monitoring(): def start_monitoring():
vrpmid = request.get_json() vrpmid = request.get_json()
data = vrpmdvdata.startMonitoring(vrpmid) data = vrpmdvdata.startMonitoring(vrpmid)
resp = Response(data, status=200, mimetype='application/json') resp = Response(data, status=200, mimetype='application/json')
return resp return resp
@app.route('/vrpmdvapi/1_0/monitorings/stop', methods=['PUT']) @app.route('/vrpmdvapi/1_0/monitorings/stop/', methods=['PATCH'])
def stop_monitoring(): def stop_monitoring():
vrpmid = request.get_json() vrpmid = request.get_json()
data = vrpmdvdata.stopMonitoring(vrpmid) data = vrpmdvdata.stopMonitoring(vrpmid)
resp = Response(data, status=200, mimetype='application/json') resp = Response(data, status=200, mimetype='application/json')
return resp return resp
@app.route('/vrpmdvapi/1_0/monitoringstatus/<id>', methods=['PATCH'])
def setStatus(id):
vrpmStatus = request.get_json()
data = vrpmdvdata.setStatus(id, vrpmStatus)
resp = Response(data, status=200, mimetype='application/json')
return resp

View File

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB