Skip to content

Commit

Permalink
Merge pull request #20 from gemini-hlsw/SCHED-574
Browse files Browse the repository at this point in the history
Sched 574
  • Loading branch information
stroncod authored Jan 12, 2024
2 parents ac70210 + 6cea149 commit d606579
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 30 deletions.
16 changes: 9 additions & 7 deletions src/components/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useRef, useEffect, useContext, SetStateAction } from 'react'
import React, { useState, useRef, useEffect, useContext, SetStateAction } from 'react'
import { useLazyQuery } from '@apollo/client'
import { scheduleQuery } from './query'
import { GlobalStateContext } from '../GlobalState/GlobalState'
Expand All @@ -11,7 +11,6 @@ import { Calendar } from 'primereact/calendar'
import { SelectButton } from 'primereact/selectbutton'
import { Toast } from 'primereact/toast'
import { Nullable } from "primereact/ts-helpers";
import { SchedulerModes } from '../../gql/graphql'
import { NightPlanType } from '../../types'


Expand All @@ -29,7 +28,7 @@ export default function ControlPanel() {

const [schedule, { loading, error, data }] = useLazyQuery(scheduleQuery)

const { setNightPlans, setPlansSummary } = useContext(GlobalStateContext)
const { setNightPlans, setPlansSummary, thesis, power, metPower, whaPower, visPower } = useContext(GlobalStateContext)

const onSaveClick = () => {
// Creates a json file with all the
Expand Down Expand Up @@ -58,8 +57,11 @@ export default function ControlPanel() {
sites: siteState,
numNightsToSchedule: 3,
mode: 'VALIDATION',


thesis: thesis,
power: power,
metPower: metPower,
visPower: visPower,
whaPower: whaPower
}
})
} else {
Expand Down Expand Up @@ -93,7 +95,7 @@ export default function ControlPanel() {
return (
<>
<Toast ref={toast}></Toast>
<Panel className="control-panel" header="Control Panel">
<Panel className="control-panel">
<Button label="RUN" icon="pi pi-play" className='p-button-success' loading={loading} onClick={onRunClick} />
<Button label="SAVE" icon="pi pi-save" loading={saveState} onClick={onSaveClick} />
<Button label="LOAD" icon="pi pi-arrow-circle-up" loading={saveState} onClick={onLoadClick} />
Expand All @@ -102,7 +104,7 @@ export default function ControlPanel() {
options={sites}
className="toggle-btn p-selectbutton p-component"
onChange={(e) => setSite(e.value)}
unselectable={false} />
allowEmpty={false} />
<Calendar
id="range"
value={datesState}
Expand Down
14 changes: 12 additions & 2 deletions src/components/ControlPanel/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ export const scheduleQuery = graphql(`
$endTime: String!,
$sites: Sites!,
$mode: SchedulerModes!,
$numNightsToSchedule: Int! ) {
$numNightsToSchedule: Int!,
$thesisFactor: Float,
$power: Int,
$metPower: Float,
$visPower: Float,
$whaPower: Float ) {
schedule(
newScheduleInput: {
startTime: $startTime,
numNightsToSchedule: $numNightsToSchedule ,
sites: $sites,
mode: $mode,
endTime: $endTime}
endTime: $endTime,
thesisFactor: $thesisFactor,
power: $power,
visPower: $visPower,
metPower: $metPower,
whaPower: $whaPower}
) {
nightPlans{
nightTimeline{
Expand Down
27 changes: 26 additions & 1 deletion src/components/GlobalState/GlobalState.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useState, ReactNode, useEffect } from "react";
import React, { createContext, useState, ReactNode} from "react";

// ------------------------------------------------------------
// Populate initial data, just for testing, should be removed
Expand All @@ -11,6 +11,16 @@ interface GlobalStateContextType {
setNightPlans: React.Dispatch<React.SetStateAction<NightPlanType[]>>;
plansSummary: object;
setPlansSummary: React.Dispatch<React.SetStateAction<[]>>;
thesis: number,
setThesis: React.Dispatch<React.SetStateAction<number>>;
power: number,
setPower: React.Dispatch<React.SetStateAction<number>>;
metPower: number,
setMetPower: React.Dispatch<React.SetStateAction<number>>;
visPower: number,
setVisPower: React.Dispatch<React.SetStateAction<number>>;
whaPower: number,
setWhaPower: React.Dispatch<React.SetStateAction<number>>;
}

export const GlobalStateContext = createContext<GlobalStateContextType>(null!);
Expand All @@ -22,6 +32,11 @@ export default function GlobalStateProvider({
}) {
const [nightPlans, setNightPlans] = useState<NightPlanType[]>([]);
const [plansSummary, setPlansSummary] = useState<object>({});
const [thesis, setThesis] = useState<number>(1.0);
const [power, setPower] = useState<number>(2);
const [metPower, setMetPower] = useState<number>(1.0);
const [visPower, setVisPower] = useState<number>(1.0);
const [whaPower, setWhaPower] = useState<number>(1.0);



Expand All @@ -32,6 +47,16 @@ export default function GlobalStateProvider({
setNightPlans,
plansSummary,
setPlansSummary,
thesis,
setThesis,
power,
setPower,
metPower,
setMetPower,
visPower,
setVisPower,
whaPower,
setWhaPower
}}
>
{children}
Expand Down
38 changes: 38 additions & 0 deletions src/components/RankerTweaker/RankerTweaker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useContext } from "react";
import { InputNumber, InputNumberValueChangeEvent } from 'primereact/inputnumber';
import { GlobalStateContext } from '../GlobalState/GlobalState'

export default function RankerTweaker () {

const { thesis, setThesis,
power, setPower,
metPower, setMetPower,
visPower, setVisPower,
whaPower, setWhaPower } = useContext(GlobalStateContext);


return (
<div className="card flex flex-wrap gap-3 p-fluid">
<div className="flex-auto">
<label htmlFor="thesis" className="font-bold block mb-2">Thesis factor</label>
<InputNumber inputId="thesis" value={thesis} onValueChange={(e: InputNumberValueChangeEvent) => setThesis(e.value)} useGrouping={false} minFractionDigits={2} maxFractionDigits={5} />
</div>
<div className="flex-auto">
<label htmlFor="power" className="font-bold block mb-2">Power factor</label>
<InputNumber inputId="power" value={power} onValueChange={(e: InputNumberValueChangeEvent) => setPower(e.value)} useGrouping={false} />
</div>
<div className="flex-auto">
<label htmlFor="metPower" className="font-bold block mb-2">MAT power</label>
<InputNumber inputId="metPower" value={metPower} onValueChange={(e: InputNumberValueChangeEvent) => setMetPower(e.value)} useGrouping={false} minFractionDigits={2} maxFractionDigits={5} />
</div>
<div className="flex-auto">
<label htmlFor="visPower" className="font-bold block mb-2">Visibility power</label>
<InputNumber inputId="visPower" value={visPower} onValueChange={(e: InputNumberValueChangeEvent) => setVisPower(e.value)} useGrouping={false} minFractionDigits={2} maxFractionDigits={5} />
</div>
<div className="flex-auto">
<label htmlFor="whaPower" className="font-bold block mb-2">WHA power</label>
<InputNumber inputId="whaPower" value={whaPower} onValueChange={(e: InputNumberValueChangeEvent) => setWhaPower(e.value)} useGrouping={false} minFractionDigits={2} maxFractionDigits={5} />
</div>
</div>
)
}
8 changes: 3 additions & 5 deletions src/components/Validation/Validation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from "react"
import React, { useContext } from "react"
import ControlPanel from "../ControlPanel/ControlPanel"
import InputsPanel from "../InputsPanel/InputsPanel"
// import NightPlansList from "../NightPlansList/NightPlansList"
Expand All @@ -12,6 +12,7 @@ import SummaryTable from "../SummaryTable/SummaryTable"

import { Panel } from "primereact/panel"
import Results from "../Results/Results"
import RankerTweaker from "../RankerTweaker/rankerTweaker"


export default function Validation() {
Expand All @@ -23,14 +24,11 @@ export default function Validation() {
<ControlPanel />
<InputsPanel />
<Panel header="Ranker Tweaker">
<p>Replace with ranker tweaker</p>
<RankerTweaker />
</Panel>
<Divider />
{(Object.keys(plansSummary).length > 0) && <>
<SummaryTable summary={plansSummary} />
<Panel header="Stats">
<p>Replace with stats... Band, Instrument, Weather</p>
</Panel>
</>}
<div className="bottom">
{nightPlans.length > 0 && <>
Expand Down
9 changes: 2 additions & 7 deletions src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
* Therefore it is highly recommended to use the babel-plugin for production.
*/
const documents = {
"\n query schedule($startTime: String!,\n $endTime: String!,\n $sites: Sites!,\n $mode: SchedulerModes!,\n $numNightsToSchedule: Int! ) {\n schedule(\n newScheduleInput: {\n startTime: $startTime, \n numNightsToSchedule: $numNightsToSchedule , \n sites: $sites, \n mode: $mode, \n endTime: $endTime}\n ) {\n nightPlans{\n nightTimeline{\n nightIndex\n timeEntriesBySite{\n site,\n timeEntries{\n startTimeSlots,\n event,\n plan{\n startTime,\n visits{\n obsId,\n endTime,\n altitude,\n atomEndIdx,\n atomStartIdx,\n startTime,\n instrument\n },\n nightStats{\n timeloss,\n planScore,\n timeloss,\n nToos,\n completionFraction,\n }\n }\n }\n }\n }\n },\n plansSummary\n }\n }\n": types.ScheduleDocument,
"\n query GetPlansBySite{\n sitePlans(site: GS) {\n nightIdx\n plansPerSite {\n site\n startTime\n endTime\n visits {\n startTime\n obsId\n atomStartIdx\n atomEndIdx\n }\n }\n }\n }\n": types.GetPlansBySiteDocument,
"\n query schedule($startTime: String!,\n $endTime: String!,\n $sites: Sites!,\n $mode: SchedulerModes!,\n $numNightsToSchedule: Int!,\n $thesisFactor: Float,\n $power: Int,\n $metPower: Float,\n $visPower: Float,\n $whaPower: Float ) {\n schedule(\n newScheduleInput: {\n startTime: $startTime, \n numNightsToSchedule: $numNightsToSchedule , \n sites: $sites, \n mode: $mode, \n endTime: $endTime,\n thesisFactor: $thesisFactor,\n power: $power,\n visPower: $visPower,\n metPower: $metPower,\n whaPower: $whaPower}\n ) {\n nightPlans{\n nightTimeline{\n nightIndex\n timeEntriesBySite{\n site,\n timeEntries{\n startTimeSlots,\n event,\n plan{\n startTime,\n visits{\n obsId,\n endTime,\n altitude,\n atomEndIdx,\n atomStartIdx,\n startTime,\n instrument\n },\n nightStats{\n timeloss,\n planScore,\n timeloss,\n nToos,\n completionFraction,\n }\n }\n }\n }\n }\n },\n plansSummary\n }\n }\n": types.ScheduleDocument,
};

/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query schedule($startTime: String!,\n $endTime: String!,\n $sites: Sites!,\n $mode: SchedulerModes!,\n $numNightsToSchedule: Int! ) {\n schedule(\n newScheduleInput: {\n startTime: $startTime, \n numNightsToSchedule: $numNightsToSchedule , \n sites: $sites, \n mode: $mode, \n endTime: $endTime}\n ) {\n nightPlans{\n nightTimeline{\n nightIndex\n timeEntriesBySite{\n site,\n timeEntries{\n startTimeSlots,\n event,\n plan{\n startTime,\n visits{\n obsId,\n endTime,\n altitude,\n atomEndIdx,\n atomStartIdx,\n startTime,\n instrument\n },\n nightStats{\n timeloss,\n planScore,\n timeloss,\n nToos,\n completionFraction,\n }\n }\n }\n }\n }\n },\n plansSummary\n }\n }\n"): (typeof documents)["\n query schedule($startTime: String!,\n $endTime: String!,\n $sites: Sites!,\n $mode: SchedulerModes!,\n $numNightsToSchedule: Int! ) {\n schedule(\n newScheduleInput: {\n startTime: $startTime, \n numNightsToSchedule: $numNightsToSchedule , \n sites: $sites, \n mode: $mode, \n endTime: $endTime}\n ) {\n nightPlans{\n nightTimeline{\n nightIndex\n timeEntriesBySite{\n site,\n timeEntries{\n startTimeSlots,\n event,\n plan{\n startTime,\n visits{\n obsId,\n endTime,\n altitude,\n atomEndIdx,\n atomStartIdx,\n startTime,\n instrument\n },\n nightStats{\n timeloss,\n planScore,\n timeloss,\n nToos,\n completionFraction,\n }\n }\n }\n }\n }\n },\n plansSummary\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query GetPlansBySite{\n sitePlans(site: GS) {\n nightIdx\n plansPerSite {\n site\n startTime\n endTime\n visits {\n startTime\n obsId\n atomStartIdx\n atomEndIdx\n }\n }\n }\n }\n"): (typeof documents)["\n query GetPlansBySite{\n sitePlans(site: GS) {\n nightIdx\n plansPerSite {\n site\n startTime\n endTime\n visits {\n startTime\n obsId\n atomStartIdx\n atomEndIdx\n }\n }\n }\n }\n"];
export function graphql(source: "\n query schedule($startTime: String!,\n $endTime: String!,\n $sites: Sites!,\n $mode: SchedulerModes!,\n $numNightsToSchedule: Int!,\n $thesisFactor: Float,\n $power: Int,\n $metPower: Float,\n $visPower: Float,\n $whaPower: Float ) {\n schedule(\n newScheduleInput: {\n startTime: $startTime, \n numNightsToSchedule: $numNightsToSchedule , \n sites: $sites, \n mode: $mode, \n endTime: $endTime,\n thesisFactor: $thesisFactor,\n power: $power,\n visPower: $visPower,\n metPower: $metPower,\n whaPower: $whaPower}\n ) {\n nightPlans{\n nightTimeline{\n nightIndex\n timeEntriesBySite{\n site,\n timeEntries{\n startTimeSlots,\n event,\n plan{\n startTime,\n visits{\n obsId,\n endTime,\n altitude,\n atomEndIdx,\n atomStartIdx,\n startTime,\n instrument\n },\n nightStats{\n timeloss,\n planScore,\n timeloss,\n nToos,\n completionFraction,\n }\n }\n }\n }\n }\n },\n plansSummary\n }\n }\n"): (typeof documents)["\n query schedule($startTime: String!,\n $endTime: String!,\n $sites: Sites!,\n $mode: SchedulerModes!,\n $numNightsToSchedule: Int!,\n $thesisFactor: Float,\n $power: Int,\n $metPower: Float,\n $visPower: Float,\n $whaPower: Float ) {\n schedule(\n newScheduleInput: {\n startTime: $startTime, \n numNightsToSchedule: $numNightsToSchedule , \n sites: $sites, \n mode: $mode, \n endTime: $endTime,\n thesisFactor: $thesisFactor,\n power: $power,\n visPower: $visPower,\n metPower: $metPower,\n whaPower: $whaPower}\n ) {\n nightPlans{\n nightTimeline{\n nightIndex\n timeEntriesBySite{\n site,\n timeEntries{\n startTimeSlots,\n event,\n plan{\n startTime,\n visits{\n obsId,\n endTime,\n altitude,\n atomEndIdx,\n atomStartIdx,\n startTime,\n instrument\n },\n nightStats{\n timeloss,\n planScore,\n timeloss,\n nToos,\n completionFraction,\n }\n }\n }\n }\n }\n },\n plansSummary\n }\n }\n"];

/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
Expand Down
Loading

0 comments on commit d606579

Please sign in to comment.