Skip to content

Commit

Permalink
Partial progress on mvt manipulator and toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
aunshx committed Sep 4, 2024
1 parent b79e71f commit 4f6cf9a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ const themeObj = {
}

const MvtGraph = ({ chartData, chartMaxData, mvtGraphNo }) => {
console.log('CHART DATA', chartData)
const { theme } = useContext(ThemeContext)

const graphTheme = theme ? themeObj : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const Manipulator = ({
toggleFaulty,
toggleLine,
}) => {
console.log('eifne', labelToggle)
return (
<div className='mt-2 rounded-md w-550p py-6 px-2 border-3p border-solid border-gray-700 dark:border-gray-50 flex flex-col gap-y-6 bg-blue-10 dark:bg-blue-450'>
<div className="flex flex-col gap-y-6">
Expand All @@ -28,13 +27,16 @@ const Manipulator = ({
<FontVarTitle title={'Toggle Line Graph:'} fontClass={'text-15p'} />
<div className='flex gap-x-7 justify-center'>
{MVT_GRAPH_LABELS.length > 0 && MVT_GRAPH_LABELS.map((title, index) => (
<ReplicaButton
title={title}
onClick={() => toggleLine(title)}
lineActive={!labelToggle[title]}
lineToggle={true}
key={index}
/>
<>
{console.log('HELLO', title, labelToggle)}
<ReplicaButton
title={title}
onClick={() => toggleLine(title)}
lineActive={labelToggle[title]}
lineToggle={true}
key={index}
/>
</>
))}
</div>
</div>
Expand Down
77 changes: 41 additions & 36 deletions src/Components/Pages/Visualizer/Graphs/MVT/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@

import { useContext, useEffect, useState } from "react";
import { VizDataHistoryContext } from "../../../../../Context/visualizer";
import { mvtGraphComputation } from "../../Ancilliary/Computation/MVT";
import ResizableContainer from "../Components/GraphContainer";
import MvtGraph from "./Components/Graph";
import Manipulator from "./Components/Manipulator";

const LABEL_TOGGLES = { "Replica 1": true, "Replica 2": true, "Replica 3": true, "Replica 4": true }

const FAULT_TOGGLES = { "Replica 1": false, "Replica 2": false, "Replica 3": false, "Replica 4": false }

const LABEL_TOGGLES = { "Replica 1": true, "Replica 2": true, "Replica 3": true, "Replica 4": true };
const FAULT_TOGGLES = { "Replica 1": false, "Replica 2": false, "Replica 3": false, "Replica 4": false };

const updateLabelToggles = (status) => {
let updatedLabel = {};
status.forEach((value, index) => {
let str = `Replica ${index + 1}`;
updatedLabel = {
...updatedLabel,
[str]: value
};
});
return updatedLabel;
}

const updateFaultToggles = (status) => {
let updatedFaultToggles = {};
status.forEach((value, index) => {
let str = `Replica ${index + 1}`;
updatedFaultToggles = {
...updatedFaultToggles,
[str]: !value
};
});
return updatedFaultToggles;
}

const Mvt = () => {
const { messageHistory, currentTransaction, replicaStatus } = useContext(VizDataHistoryContext)

const { messageHistory, currentTransaction, replicaStatus } = useContext(VizDataHistoryContext);
const [messageChartData, setMessageChartData] = useState([]);
const [chartMaxData, setChartMaxData] = useState({});

const [labelToggle, setLabelToggle] = useState(LABEL_TOGGLES);
const [labelToggleFaulty, setLabelToggleFaulty] = useState(FAULT_TOGGLES);

const [resetGraph, setResetGraph] = useState(0);
const [isLoading, setIsLoading] = useState(false);

const updateGraph = () => {
let value = resetGraph;
value = value + 1;
setResetGraph(value);
}
};

const toggleFaulty = (label) => {
setLabelToggleFaulty((prevLabels) => {
Expand All @@ -39,44 +57,38 @@ const Mvt = () => {
const setFaulty = async (label) => {
try {
let response = await fetch('http://localhost:1850' + String(label.charAt(label.length - 1)) + '/make_faulty');


console.log(response.body());
} catch (error) {
//console.error('Error toggling faulty:', error);
console.error('Error toggling faulty:', error);
}
}
};

setFaulty(label);

updateGraph();
};

const toggleLine = (label) => {
setLabelToggle((prevLabels) => {
const updatedLabels = { ...prevLabels };
updatedLabels[label] = !updatedLabels[label];
return updatedLabels;
return updatedLabels;
});
updateGraph();
};


const chartMaxDataUpdate = (value) => setChartMaxData(value);
const messageChartDataUpdate = (value) => setMessageChartData(value);

useEffect(() => {
const transactionData = messageHistory[currentTransaction];
setLabelToggleFaulty(replicaStatus)
setLabelToggle(replicaStatus)

replicaStatus.length > 0 && replicaStatus.forEach((value, index) => {
if (!value) {
toggleFaulty(`Replica ${index + 1}`)
toggleLine(`Replica ${index + 1}`)
}
});
const updatedLabelToggles = updateLabelToggles(replicaStatus);
const updatedFaultToggles = updateFaultToggles(replicaStatus);

setLabelToggle(updatedLabelToggles);
setLabelToggleFaulty(updatedFaultToggles);

const { pointData, maxPointData } = mvtGraphComputation(transactionData, labelToggle, chartMaxDataUpdate, messageChartDataUpdate)
const { pointData, maxPointData } = mvtGraphComputation(transactionData, updatedLabelToggles, chartMaxDataUpdate, messageChartDataUpdate);

chartMaxDataUpdate(maxPointData);
messageChartDataUpdate(pointData);
Expand All @@ -88,7 +100,7 @@ const Mvt = () => {
<div className="grid grid-cols-2 gap-x-6 w-full">
<ResizableContainer title={'Prepare Messages v Time'} >
<div className='relative w-full h-full pl-4 pr-2 pb-6'>
{(isLoading) ? (
{isLoading ? (
<div className='loader'>
<div>MVT</div>
<div className='inner' />
Expand All @@ -100,7 +112,7 @@ const Mvt = () => {
</ResizableContainer>
<ResizableContainer title={'Commit Messages v Time'}>
<div className='relative w-full h-full pl-4 pr-2 pb-6'>
{(isLoading) ? (
{isLoading ? (
<div className='loader'>
<div>MVT</div>
<div className='inner' />
Expand All @@ -123,11 +135,4 @@ const Mvt = () => {
);
};

const index = () => {
return (
<Mvt />
);
};


export default index;
export default Mvt;

0 comments on commit 4f6cf9a

Please sign in to comment.