Skip to content

Commit

Permalink
Only show rerun failed missions when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Sep 18, 2023
1 parent 91b292a commit 359ef23
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 38 deletions.
155 changes: 153 additions & 2 deletions backend/api/Database/Context/InitDb.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Api.Database.Models;
using Api.Controllers.Models;
using Api.Database.Models;

namespace Api.Database.Context;

Expand All @@ -10,6 +11,7 @@ public static class InitDb
private static readonly List<Deck> decks = GetDecks();
private static readonly List<Area> areas = GetAreas();
private static readonly List<Source> sources = GetSources();
private static readonly List<MissionTask> tasks = GetMissionTasks();
private static readonly List<MissionDefinition> missionDefinitions = GetMissionDefinitions();
private static readonly List<MissionRun> missionRuns = GetMissionRuns();

Expand Down Expand Up @@ -215,6 +217,87 @@ private static List<MissionDefinition> GetMissionDefinitions()
return new List<MissionDefinition>(new[] { missionDefinition1, missionDefinition2, missionDefinition3 });
}

private static List<MissionTask> GetMissionTasks()
{
var task1 = new MissionTask(
new EchoTag
{
Id = 2,
TagId = "ABCD",
PoseId = 2,
PlanOrder = 0,
Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f),
URL = new Uri(
$"https://stid.equinor.com/jsv/tag?tagNo=ABCD"
),
Inspections = new List<EchoInspection>
{
new()
}
}, new Position(1.0f, 1.0f, 1.0f));
var task2 = new MissionTask(
new EchoTag
{
Id = 2,
TagId = "ABCD",
PoseId = 2,
PlanOrder = 0,
Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f),
URL = new Uri(
$"https://stid.equinor.com/jsv/tag?tagNo=ABCD"
),
Inspections = new List<EchoInspection>
{
new()
}
}, new Position(1.0f, 1.0f, 1.0f))
{
Status = Models.TaskStatus.Failed
};

var task3 = new MissionTask(
new EchoTag
{
Id = 2,
TagId = "ABCD",
PoseId = 2,
PlanOrder = 0,
Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f),
URL = new Uri(
$"https://stid.equinor.com/jsv/tag?tagNo=ABCD"
),
Inspections = new List<EchoInspection>
{
new()
}
}, new Position(1.0f, 1.0f, 1.0f))
{
Status = Models.TaskStatus.PartiallySuccessful
};

var task4 = new MissionTask(
new EchoTag
{
Id = 2,
TagId = "ABCD",
PoseId = 2,
PlanOrder = 0,
Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f),
URL = new Uri(
$"https://stid.equinor.com/jsv/tag?tagNo=ABCD"
),
Inspections = new List<EchoInspection>
{
new()
}
}, new Position(1.0f, 1.0f, 1.0f))
{
Status = Models.TaskStatus.Cancelled
};

return new List<MissionTask> { task1, task2, task3, task4 };
}

private static List<MissionRun> GetMissionRuns()
{
var missionRun1 = new MissionRun
Expand Down Expand Up @@ -257,9 +340,77 @@ private static List<MissionRun> GetMissionRuns()
Map = new MapMetadata()
};

var missionRun4 = new MissionRun
{
Name = "Placeholder Mission 4",
Robot = robots[2],
InstallationCode = areas[1].Installation.InstallationCode,
Area = areas[1],
MissionId = missionDefinitions[1].Id,
Status = MissionStatus.Failed,
DesiredStartTime = DateTimeOffset.UtcNow,
Tasks = new List<MissionTask>
{
tasks[0],
tasks[1]
},
Map = new MapMetadata()
};

var missionRun5 = new MissionRun
{
Name = "Placeholder Mission 5",
Robot = robots[2],
InstallationCode = areas[1].Installation.InstallationCode,
Area = areas[1],
MissionId = missionDefinitions[1].Id,
Status = MissionStatus.PartiallySuccessful,
DesiredStartTime = DateTimeOffset.UtcNow,
Tasks = new List<MissionTask>
{
tasks[0],
tasks[2]
},
Map = new MapMetadata()
};

var missionRun6 = new MissionRun
{
Name = "Placeholder Mission 6",
Robot = robots[2],
InstallationCode = areas[1].Installation.InstallationCode,
Area = areas[1],
MissionId = missionDefinitions[1].Id,
Status = MissionStatus.Cancelled,
DesiredStartTime = DateTimeOffset.UtcNow,
Tasks = new List<MissionTask>
{
tasks[0],
tasks[3]
},
Map = new MapMetadata()
};

var missionRun7 = new MissionRun
{
Name = "Says failed but all tasks succeeded",
Robot = robots[2],
InstallationCode = areas[1].Installation.InstallationCode,
Area = areas[1],
MissionId = missionDefinitions[1].Id,
Status = MissionStatus.Failed,
DesiredStartTime = DateTimeOffset.UtcNow,
Tasks = new List<MissionTask>
{
tasks[0],
tasks[0]
},
Map = new MapMetadata()
};

missionDefinitions[1].LastRun = missionRun3;

return new List<MissionRun>(new[] { missionRun1, missionRun2, missionRun3 });
return new List<MissionRun>(new[] { missionRun1, missionRun2, missionRun3, missionRun4, missionRun5, missionRun6, missionRun7 });
}

public static void PopulateDb(FlotillaDbContext context)
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ export class BackendAPICaller {
static async reRunMission(missionId: string, failedTasksOnly: boolean = false): Promise<Mission> {
let mission = await this.getMissionRunById(missionId)

// TODO: utilise reschedule endpoint instead of copying

if (failedTasksOnly) {
mission.tasks = mission.tasks.filter(
(task) => task.status !== TaskStatus.PartiallySuccessful && task.status !== TaskStatus.Successful
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mission } from 'models/Mission'
import { Mission, MissionStatus } from 'models/Mission'
import { Button, EdsProvider, Icon, Menu, Tooltip } from '@equinor/eds-core-react'
import { Icons } from 'utils/icons'
import { tokens } from '@equinor/eds-tokens'
Expand All @@ -8,6 +8,7 @@ import { useNavigate } from 'react-router-dom'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import styled from 'styled-components'
import { useRef, useState } from 'react'
import { TaskStatus } from 'models/Task'

const Centered = styled.div`
display: flex;
Expand Down Expand Up @@ -77,9 +78,13 @@ export function MissionRestartButton({ mission }: MissionProps) {
<Menu.Item onClick={() => startReRun(ReRunOptions.ReRun)}>
{TranslateText('Re-run full mission')}
</Menu.Item>
<Menu.Item onClick={() => startReRun(ReRunOptions.ReRunFailed)}>
{TranslateText('Re-run failed and cancelled tasks in the mission')}
</Menu.Item>
{mission.tasks.some(
(t) => t.status !== TaskStatus.PartiallySuccessful && t.status !== TaskStatus.Successful
) && (
<Menu.Item onClick={() => startReRun(ReRunOptions.ReRunFailed)}>
{TranslateText('Re-run failed and cancelled tasks in the mission')}
</Menu.Item>
)}
</Menu>
</EdsProvider>
</Centered>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,22 @@ export function MissionHistoryView({ refreshInterval }: RefreshProps) {
<Typography variant="h1">{TranslateText('Mission History')}</Typography>
<FilterSection />
<Table>
<Table>
<Table.Head sticky>
<Table.Row>
<Table.Cell>{TranslateText('Status')}</Table.Cell>
<Table.Cell>{TranslateText('Name')}</Table.Cell>
<Table.Cell>{TranslateText('Robot')}</Table.Cell>
<Table.Cell>{TranslateText('Completion Time')}</Table.Cell>
</Table.Row>
</Table.Head>
{isLoading && (
<Table.Caption captionSide={'bottom'}>
<StyledLoading>
<CircularProgress />
</StyledLoading>
</Table.Caption>
)}
{!isLoading && <Table.Body>{missionsDisplay}</Table.Body>}
</Table>
<Table.Head sticky>
<Table.Row>
<Table.Cell>{TranslateText('Status')}</Table.Cell>
<Table.Cell>{TranslateText('Name')}</Table.Cell>
<Table.Cell>{TranslateText('Robot')}</Table.Cell>
<Table.Cell>{TranslateText('Completion Time')}</Table.Cell>
</Table.Row>
</Table.Head>
{isLoading && (
<Table.Caption captionSide={'bottom'}>
<StyledLoading>
<CircularProgress />
</StyledLoading>
</Table.Caption>
)}
{!isLoading && <Table.Body>{missionsDisplay}</Table.Body>}
<Table.Caption captionSide={'bottom'}>
{paginationDetails && paginationDetails.TotalPages > 1 && !isResettingPage && PaginationComponent()}
</Table.Caption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ export function TaskTable({ mission }: MissionProps) {
}

function renderTasks(tasks: Task[]) {
var rows = tasks?.map(function (task) {
var rows = tasks.map((task) => {
// Workaround for current bug in echo
var order: number = task.taskOrder < 214748364 ? task.taskOrder + 1 : 1
const order: number = task.taskOrder < 214748364 ? task.taskOrder + 1 : 1
const rowStyle =
task.status === TaskStatus.InProgress || task.status === TaskStatus.Paused
? { background: tokens.colors.infographic.primary__mist_blue.hex }
: {}
const markerColors = GetColorsFromTaskStatus(task.status)
return (
<Table.Row key={order} style={rowStyle}>
<Table.Row key={task.id} style={rowStyle}>
<Table.Cell>
<Chip style={{ background: markerColors.fillColor }}>
<Typography variant="body_short_bold" style={{ color: markerColors.textColor }}>
{order}
</Typography>
</Chip>
</Table.Cell>
<Table.Cell> {renderTagId(task)}</Table.Cell>
<Table.Cell> {renderDescription(task)}</Table.Cell>
<Table.Cell> {renderTagId(task)} </Table.Cell>
<Table.Cell> {renderDescription(task)} </Table.Cell>
<Table.Cell> {renderInspectionTypes(task)} </Table.Cell>
<Table.Cell>
<TaskStatusDisplay status={task.status} />
Expand All @@ -69,30 +69,35 @@ function renderTasks(tasks: Task[]) {
}

function renderTagId(task: Task) {
if (!task.tagId) return <Typography>{'N/A'}</Typography>
if (!task.tagId) return <Typography key={task.id + 'tagId'}>{'N/A'}</Typography>

if (task.echoTagLink)
return (
<Typography link href={task.echoTagLink} target="_blank">
<Typography key={task.id + 'tagId'} link href={task.echoTagLink} target="_blank">
{task.tagId!}
</Typography>
)
else return <Typography>{task.tagId!}</Typography>
else return <Typography key={task.id + 'tagId'}>{task.tagId!}</Typography>
}

function renderDescription(task: Task) {
if (!task.description) return <Typography>{'N/A'}</Typography>
return <Typography>{task.description}</Typography>
if (!task.description) return <Typography key={task.id + 'descr'}>{'N/A'}</Typography>
return <Typography key={task.id + 'descr'}>{task.description}</Typography>
}

function renderInspectionTypes(task: Task) {
return task.inspections?.map(function (inspection) {
if (inspection.inspectionUrl)
return (
<Typography link href={inspection.inspectionUrl}>
<Typography key={task.id + inspection.id + 'insp'} link href={inspection.inspectionUrl}>
{TranslateTextWithContext(inspection.inspectionType as string)}
</Typography>
)
else
return (
<Typography key={task.id + inspection.id + 'insp'}>
{TranslateTextWithContext(inspection.inspectionType as string)}
</Typography>
)
else return <Typography>{TranslateTextWithContext(inspection.inspectionType as string)}</Typography>
})
}

0 comments on commit 359ef23

Please sign in to comment.