Skip to content

Commit 8ca8401

Browse files
committed
working - target stations use filter
1 parent 4751a02 commit 8ca8401

File tree

9 files changed

+105
-288
lines changed

9 files changed

+105
-288
lines changed

app/components/InstrumentsDisplay.test.ts

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
import { createInstrumentGroups } from "@/app/components/InstrumentsDisplay";
2-
import { targetStation } from "@/app/types";
2+
import { instList } from "@/app/types";
33

44
test("createInstrumentGroups adds two instruments from different target stations to the same science group", () => {
55
const instrument1Name = "INST1";
66
const instrument2Name = "INST2";
77
const commonScienceGroup = "MOLSPEC";
88
const instrument1 = {
99
name: instrument1Name,
10-
scienceGroups: [commonScienceGroup],
10+
groups: [commonScienceGroup],
11+
targetStation: "TS0",
12+
hostName: "",
13+
pvPrefix: "",
14+
isScheduled: true,
15+
seci: false,
16+
runStatePV: "",
17+
runStateValue: "",
1118
};
1219
const instrument2 = {
1320
name: instrument2Name,
14-
scienceGroups: [commonScienceGroup],
21+
groups: [commonScienceGroup],
22+
targetStation: "TS0",
23+
hostName: "",
24+
pvPrefix: "",
25+
isScheduled: true,
26+
seci: false,
27+
runStatePV: "",
28+
runStateValue: "",
1529
};
16-
const targetStations: Array<targetStation> = [
17-
{ targetStation: "TS0", instruments: [instrument1] },
18-
{ targetStation: "TS3", instruments: [instrument2] },
19-
];
30+
const targetStations: instList = [instrument1, instrument2];
2031
const result = createInstrumentGroups(targetStations);
2132

2233
expect(result.get(commonScienceGroup)!.sort()).toStrictEqual(
@@ -29,13 +40,27 @@ test("createInstrumentGroups ignores instrument without any groups", () => {
2940
const commonScienceGroup = "MOLSPEC";
3041
const instrument1 = {
3142
name: instrument1Name,
32-
scienceGroups: [commonScienceGroup],
43+
groups: [commonScienceGroup],
44+
targetStation: "TS0",
45+
hostName: "",
46+
pvPrefix: "",
47+
isScheduled: true,
48+
seci: false,
49+
runStatePV: "",
50+
runStateValue: "",
3351
};
34-
const instrument2 = { name: "someinstrumentwithnogroups", scienceGroups: [] };
35-
const targetStations: Array<targetStation> = [
36-
{ targetStation: "TS0", instruments: [instrument1] },
37-
{ targetStation: "TS3", instruments: [instrument2] },
38-
];
52+
const instrument2 = {
53+
name: "someinstrumentwithnogroups",
54+
targetStation: "TS0",
55+
hostName: "",
56+
pvPrefix: "",
57+
isScheduled: true,
58+
seci: false,
59+
runStatePV: "",
60+
runStateValue: "",
61+
groups: [],
62+
};
63+
const targetStations: instList = [instrument1, instrument2];
3964
const result = createInstrumentGroups(targetStations);
4065

4166
expect(result.get(commonScienceGroup)!.sort()).toStrictEqual(
@@ -48,16 +73,27 @@ test("createInstrumentGroups ignores instrument which is a support machine", ()
4873
const commonScienceGroup = "MOLSPEC";
4974
const instrument1 = {
5075
name: instrument1Name,
51-
scienceGroups: [commonScienceGroup],
76+
groups: [commonScienceGroup],
77+
targetStation: "TS0",
78+
hostName: "",
79+
pvPrefix: "",
80+
isScheduled: true,
81+
seci: false,
82+
runStatePV: "",
83+
runStateValue: "",
5284
};
5385
const instrument2 = {
5486
name: "someinstrumentwithnogroups",
55-
scienceGroups: ["SUPPORT"],
87+
groups: ["SUPPORT"],
88+
targetStation: "TS3",
89+
hostName: "",
90+
pvPrefix: "",
91+
isScheduled: true,
92+
seci: false,
93+
runStatePV: "",
94+
runStateValue: "",
5695
};
57-
const targetStations: Array<targetStation> = [
58-
{ targetStation: "TS0", instruments: [instrument1] },
59-
{ targetStation: "TS3", instruments: [instrument2] },
60-
];
96+
const targetStations: instList = [instrument1, instrument2];
6197
const result = createInstrumentGroups(targetStations);
6298

6399
expect(result.get(commonScienceGroup)!.sort()).toStrictEqual(

app/components/InstrumentsDisplay.tsx

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ import {
44
IfcPVWSMessage,
55
IfcPVWSRequest,
66
instList,
7-
instListEntryWithRunstatePVandValue,
87
PVWSRequestType,
98
} from "@/app/types";
109
import useWebSocket from "react-use-websocket";
1110
import { instListPV, instListSubscription, socketURL } from "@/app/commonVars";
1211
import { instListFromBytes } from "@/app/components/dehex_and_decompress";
13-
import {
14-
updateInstrumentRunstate,
15-
updateInstrumentRunstatePV,
16-
updateTargetStationBeamCurrent,
17-
} from "@/app/wall/utils";
1812
import TargetStation from "@/app/components/TargetStation";
1913
import ScienceGroup from "@/app/components/ScienceGroup";
2014

@@ -23,11 +17,8 @@ const instrumentsExcludeList = ["SUPPORT"];
2317

2418
export function createInstrumentGroups(
2519
instruments: instList,
26-
): Map<string, Array<instListEntryWithRunstatePVandValue>> {
27-
let newInstrumentGroups: Map<
28-
string,
29-
Array<instListEntryWithRunstatePVandValue>
30-
> = new Map();
20+
): Map<string, instList> {
21+
let newInstrumentGroups: Map<string, instList> = new Map();
3122
for (const inst of instruments) {
3223
for (const group of inst.groups) {
3324
if (!instrumentsExcludeList.includes(group)) {
@@ -42,27 +33,6 @@ export function createInstrumentGroups(
4233
return newInstrumentGroups;
4334
}
4435

45-
export function createTargetStations(
46-
instruments: instList,
47-
): Map<string, Array<instListEntryWithRunstatePVandValue>> {
48-
let newInstrumentGroups: Map<
49-
string,
50-
Array<instListEntryWithRunstatePVandValue>
51-
> = new Map();
52-
for (const inst of instruments) {
53-
for (const group of inst.targetStation) {
54-
if (!instrumentsExcludeList.includes(group)) {
55-
if (!newInstrumentGroups.has(group)) {
56-
// This is a new science group so create a new entry
57-
newInstrumentGroups.set(group, []);
58-
}
59-
newInstrumentGroups.get(group)!.push(inst);
60-
}
61-
}
62-
}
63-
return newInstrumentGroups;
64-
}
65-
6636
/* c8 ignore start */
6737
export default function InstrumentsDisplay({
6838
sortByGroups = false,
@@ -73,7 +43,7 @@ export default function InstrumentsDisplay({
7343

7444
const ts1BeamCurrentPv = "AC:TS1:BEAM:CURR";
7545
const ts2BeamCurrentPv = "AC:TS2:BEAM:CURR";
76-
const muonTargetCurrentPv = "AC:MUON:BEAM:CURR"; //TODO make this exist
46+
const muonTargetCurrentPv = "AC:MUON:BEAM:CURR";
7747

7848
const [instList, setInstList] = useState<instList>([]);
7949

@@ -140,7 +110,7 @@ export default function InstrumentsDisplay({
140110
setMuonCurrent(updatedPVnum);
141111
}
142112
}
143-
}, [lastJsonMessage, sendJsonMessage]);
113+
}, [lastJsonMessage, sendJsonMessage, instList]);
144114

145115
return (
146116
<div>
@@ -152,17 +122,38 @@ export default function InstrumentsDisplay({
152122
<ScienceGroup key={name} name={name} instruments={instruments} />
153123
);
154124
})}
155-
{!sortByGroups &&
156-
instList.map((targetStation) => {
157-
return (
158-
<TargetStation
159-
key={targetStation.targetStation}
160-
name={targetStation.targetStation}
161-
instruments={targetStation.instruments}
162-
beamCurrent={targetStation.beamCurrent}
163-
/>
164-
);
165-
})}
125+
{!sortByGroups && (
126+
<>
127+
<TargetStation
128+
name={"TS1"}
129+
instruments={instList.filter(
130+
(instrument) => instrument.targetStation == "TS1",
131+
)}
132+
beamCurrent={ts1Current}
133+
/>
134+
<TargetStation
135+
name={"MUON"}
136+
instruments={instList.filter(
137+
(instrument) => instrument.targetStation == "MUON",
138+
)}
139+
beamCurrent={muonCurrent}
140+
/>
141+
<TargetStation
142+
name={"TS2"}
143+
instruments={instList.filter(
144+
(instrument) => instrument.targetStation == "TS2",
145+
)}
146+
beamCurrent={ts2Current}
147+
/>
148+
<TargetStation
149+
name={"MISC"}
150+
instruments={instList.filter(
151+
(instrument) => instrument.targetStation == "MISC",
152+
)}
153+
beamCurrent={undefined}
154+
/>
155+
</>
156+
)}
166157
</div>
167158
);
168159
}

app/components/TargetStation.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import InstrumentWallCard from "./InstrumentWallCard";
22

3-
import {
4-
IfcInstrumentStatus,
5-
instListEntryWithRunstatePVandValue,
6-
} from "@/app/types";
3+
import { instListEntryWithRunstatePVandValue } from "@/app/types";
74

85
export default function TargetStation({
96
name,

app/components/__snapshots__/InstrumentWallCard.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`renders instrumentwallcard unchanged 1`] = `
77
>
88
<a
99
class="flex items-center justify-center text-center p-3 w-36 max-h-12 rounded-lg shadow-sm border-2 border-gray-700 dark:border-gray-200 hover:shadow-lg hover:border-black dark:hover:border-gray-700 transition-all duration-200
10-
bg-[#90EE90] text-black"
10+
bg-[#F08080] text-black"
1111
href="/instrument?name=Instrument"
1212
target="_blank"
1313
>
@@ -22,7 +22,7 @@ exports[`renders instrumentwallcard unchanged 1`] = `
2222
<span
2323
class="text-xs "
2424
>
25-
RUNNING
25+
UNKNOWN
2626
</span>
2727
</div>
2828
</a>

app/components/__snapshots__/ScienceGroup.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exports[`renders sciencegroup unchanged 1`] = `
1818
>
1919
<a
2020
class="flex items-center justify-center text-center p-3 w-36 max-h-12 rounded-lg shadow-sm border-2 border-gray-700 dark:border-gray-200 hover:shadow-lg hover:border-black dark:hover:border-gray-700 transition-all duration-200
21-
bg-[#90EE90] text-black"
21+
bg-[#F08080] text-black"
2222
href="/instrument?name=Instrument"
2323
target="_blank"
2424
>
@@ -33,7 +33,7 @@ exports[`renders sciencegroup unchanged 1`] = `
3333
<span
3434
class="text-xs "
3535
>
36-
RUNNING
36+
UNKNOWN
3737
</span>
3838
</div>
3939
</a>
@@ -43,7 +43,7 @@ exports[`renders sciencegroup unchanged 1`] = `
4343
>
4444
<a
4545
class="flex items-center justify-center text-center p-3 w-36 max-h-12 rounded-lg shadow-sm border-2 border-gray-700 dark:border-gray-200 hover:shadow-lg hover:border-black dark:hover:border-gray-700 transition-all duration-200
46-
bg-[#DAA520] text-black"
46+
bg-[#F08080] text-black"
4747
href="/instrument?name=Instrument2"
4848
target="_blank"
4949
>
@@ -58,7 +58,7 @@ exports[`renders sciencegroup unchanged 1`] = `
5858
<span
5959
class="text-xs "
6060
>
61-
WAITING
61+
UNKNOWN
6262
</span>
6363
</div>
6464
</a>

app/components/__snapshots__/TargetStation.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exports[`renders targetstation unchanged 1`] = `
2020
>
2121
<a
2222
class="flex items-center justify-center text-center p-3 w-36 max-h-12 rounded-lg shadow-sm border-2 border-gray-700 dark:border-gray-200 hover:shadow-lg hover:border-black dark:hover:border-gray-700 transition-all duration-200
23-
bg-green-900 text-white"
23+
bg-[#F08080] text-black"
2424
href="/instrument?name=Instrument"
2525
target="_blank"
2626
>
@@ -35,7 +35,7 @@ exports[`renders targetstation unchanged 1`] = `
3535
<span
3636
class="text-xs "
3737
>
38-
RESUMING
38+
UNKNOWN
3939
</span>
4040
</div>
4141
</a>
@@ -45,7 +45,7 @@ exports[`renders targetstation unchanged 1`] = `
4545
>
4646
<a
4747
class="flex items-center justify-center text-center p-3 w-36 max-h-12 rounded-lg shadow-sm border-2 border-gray-700 dark:border-gray-200 hover:shadow-lg hover:border-black dark:hover:border-gray-700 transition-all duration-200
48-
bg-[#FFFF00] text-black"
48+
bg-[#F08080] text-black"
4949
href="/instrument?name=Instrument2"
5050
target="_blank"
5151
>
@@ -60,7 +60,7 @@ exports[`renders targetstation unchanged 1`] = `
6060
<span
6161
class="text-xs "
6262
>
63-
VETOING
63+
UNKNOWN
6464
</span>
6565
</div>
6666
</a>

app/types.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,6 @@ export interface IfcPVWSRequest {
7575
pvs: Array<string>;
7676
}
7777

78-
// export interface IfcInstrumentStatus {
79-
// /**
80-
// * Instrument status used for the wall display. Contains runstate PV and current runstate.
81-
// */
82-
// name: string; // Name of the instrument
83-
// runstate?: string; // Runstate
84-
// runstatePV?: string; // Runstate PV address
85-
// scienceGroups?: Array<string>;
86-
// }
87-
88-
// Column[Row[labelPV, valuePV]]
8978
export type DashboardArr = Array<Array<Array<IfcPV>>>;
9079

9180
export interface ConfigOutput {
@@ -147,16 +136,10 @@ export interface ConfigOutputIocMacro {
147136
value: string;
148137
}
149138

150-
// export interface targetStation {
151-
// targetStation: string;
152-
// beamCurrentPv?: string;
153-
// beamCurrent?: number | null;
154-
// instruments: Array<IfcInstrumentStatus>;
155-
// }
156-
157139
export interface instListEntry {
158-
/*
159-
TODO
140+
/**
141+
* InstList entry ie. a single item in the instlist array created
142+
* by https://github.com/ISISComputingGroup/EPICS-inst_servers/blob/master/scripts/set_instrument_list.py
160143
*/
161144
name: string;
162145
hostName: string;

0 commit comments

Comments
 (0)