-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
οΈππ β [SSM-135 SSM-130 SSM-138]: Cloud classification aggregator added
- Loading branch information
1 parent
a0b5ab7
commit cc1d570
Showing
7 changed files
with
262 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ down-full: | |
|
||
deploy-test: | ||
docker-compose build && yarn build && vercel | ||
|
||
up-light: | ||
docker-compose up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
components/Structures/Missions/Astronomers/SatellitePhotos/P4/P4Aggregator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from "react"; | ||
|
||
type Anomaly = { | ||
id: number; | ||
content: string | null; | ||
anomalytype: string | null; | ||
mass: number | null; | ||
radius: number | null; | ||
density: number | null; | ||
gravity: number | null; | ||
temperature: number | null; | ||
orbital_period: number | null; | ||
avatar_url: string | null; | ||
created_at: string; | ||
}; | ||
|
||
interface Classification { | ||
id: number; | ||
content: string | null; | ||
author: string | null; | ||
anomaly: Anomaly | null; | ||
media: (string | { uploadUrl?: string })[] | null; | ||
classificationtype: string | null; | ||
classificationConfiguration?: any; | ||
created_at: string; | ||
title?: string; | ||
votes?: number; | ||
category?: string; | ||
tags?: string[]; | ||
images?: string[]; | ||
relatedClassifications?: Classification[]; | ||
annotationOptions?: any[]; // Add annotationOptions to the Classification type to avoid errors | ||
}; | ||
|
||
export interface SatellitePlanetFourClassification extends Classification { | ||
annotationOptions: any[]; | ||
classificationConfiguration?: any; // Ensure it's optional here if required | ||
} | ||
|
||
|
||
interface SatellitePlanetFourAggregatorProps { | ||
classifications: SatellitePlanetFourClassification[]; | ||
} | ||
|
||
const SatellitePlanetFourAggregator: React.FC<SatellitePlanetFourAggregatorProps> = ({ classifications }) => { | ||
return ( | ||
<div className="mt-6"> | ||
<h3 className="text-xl font-bold">Satellite Planet Four Classifications</h3> | ||
{classifications.length === 0 ? ( | ||
<p>No satellite classifications available.</p> | ||
) : ( | ||
classifications.map((classification) => ( | ||
<div key={classification.id} className="mt-4 p-4 border border-gray-200 rounded-md shadow-md bg-[#2C4F64]"> | ||
<h4 className="font-bold text-lg">Classification #{classification.id}</h4> | ||
<p className="mt-2 text-sm">Annotation Options: {classification.annotationOptions.join(", ")}</p> | ||
{classification.classificationConfiguration && ( | ||
<pre className="bg-gray-800 text-white p-2 rounded-md"> | ||
{JSON.stringify(classification.classificationConfiguration, null, 2)} | ||
</pre> | ||
)} | ||
</div> | ||
)) | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SatellitePlanetFourAggregator; |
149 changes: 149 additions & 0 deletions
149
components/Structures/Missions/Meteorologists/Cloudspotting/CloudAggregator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
"use client"; | ||
|
||
import React, { useState } from "react"; | ||
|
||
interface Classification { | ||
id: number; | ||
classificationConfiguration?: ClassificationConfiguration; | ||
} | ||
|
||
interface ClassificationConfiguration { | ||
createdBy?: number | null; | ||
activePlanet?: number; | ||
additionalFields?: Record<string, any>; | ||
annotationOptions?: string[]; | ||
parentPlanetLocation?: string; | ||
classificationOptions?: Record<string, Record<string, boolean>>; | ||
} | ||
|
||
interface AggregatedCloud { | ||
annotationOptions: Record<string, number>; | ||
classificationOptions: Record<string, Record<string, number>>; | ||
additionalFields: Record<string, Set<string>>; | ||
} | ||
|
||
const aggregateCloudClassifications = ( | ||
classifications: Classification[] | ||
): AggregatedCloud => { | ||
const aggregated: AggregatedCloud = { | ||
annotationOptions: {}, | ||
classificationOptions: {}, | ||
additionalFields: {}, | ||
}; | ||
|
||
classifications.forEach(({ classificationConfiguration }) => { | ||
if (!classificationConfiguration) return; | ||
|
||
classificationConfiguration.annotationOptions?.forEach((option) => { | ||
const match = option.match(/(.+?)\s*\(x(\d+)\)/); | ||
if (match) { | ||
const [, name, count] = match; | ||
aggregated.annotationOptions[name] = | ||
(aggregated.annotationOptions[name] || 0) + parseInt(count); | ||
} else { | ||
aggregated.annotationOptions[option] = | ||
(aggregated.annotationOptions[option] || 0) + 1; | ||
} | ||
}); | ||
|
||
Object.entries(classificationConfiguration.classificationOptions || {}).forEach( | ||
([category, values]) => { | ||
if (!aggregated.classificationOptions[category]) { | ||
aggregated.classificationOptions[category] = {}; | ||
} | ||
Object.entries(values).forEach(([key, value]) => { | ||
if (value) { | ||
aggregated.classificationOptions[category][key] = | ||
(aggregated.classificationOptions[category][key] || 0) + 1; | ||
} | ||
}); | ||
} | ||
); | ||
|
||
Object.entries(classificationConfiguration.additionalFields || {}).forEach( | ||
([key, value]) => { | ||
if (!aggregated.additionalFields[key]) { | ||
aggregated.additionalFields[key] = new Set(); | ||
} | ||
aggregated.additionalFields[key].add(value); | ||
} | ||
); | ||
}); | ||
|
||
return aggregated; | ||
}; | ||
|
||
const CloudClassificationSummary: React.FC<{ classifications: Classification[] }> = ({ | ||
classifications, | ||
}) => { | ||
const aggregatedData = aggregateCloudClassifications(classifications); | ||
const [showAggregated, setShowAggregated] = useState(true); | ||
|
||
return ( | ||
<div className="p-4 border border-gray-200 rounded-md shadow-md bg-[#2C4F64] text-white"> | ||
<div className="flex justify-between items-center"> | ||
<h3 className="text-xl font-bold">Cloud Classification Summary</h3> | ||
<button | ||
onClick={() => setShowAggregated(!showAggregated)} | ||
className="px-3 py-1 bg-gray-700 hover:bg-gray-600 rounded-md" | ||
> | ||
{showAggregated ? "Show Individual" : "Show Aggregated"} | ||
</button> | ||
</div> | ||
|
||
{showAggregated ? ( | ||
<div> | ||
<div className="mt-4"> | ||
<h4 className="font-bold">Annotation Options</h4> | ||
<ul> | ||
{Object.entries(aggregatedData.annotationOptions).map(([option, count]) => ( | ||
<li key={option}> | ||
{option} (x{count}) | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
|
||
<div className="mt-4"> | ||
<h4 className="font-bold">Classification Options</h4> | ||
<ul> | ||
{Object.entries(aggregatedData.classificationOptions).map(([category, values]) => ( | ||
<li key={category}> | ||
<strong>{category || "General"}</strong>:{" "} | ||
{Object.entries(values) | ||
.map(([key, count]) => `${key} (x${count})`) | ||
.join(", ")} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
|
||
<div className="mt-4"> | ||
<h4 className="font-bold">Additional Fields</h4> | ||
<ul> | ||
{Object.entries(aggregatedData.additionalFields).map(([key, values]) => ( | ||
<li key={key}> | ||
<strong>{key}</strong>: {[...values].join(", ")} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
) : ( | ||
<div className="mt-4"> | ||
<h4 className="font-bold">Individual Classifications</h4> | ||
{classifications.map((classification) => ( | ||
<div key={classification.id} className="p-3 border border-gray-300 rounded-md mt-2"> | ||
<strong>Classification #{classification.id}</strong> | ||
<pre className="mt-2 bg-gray-800 p-2 rounded-md text-xs"> | ||
{JSON.stringify(classification.classificationConfiguration, null, 2)} | ||
</pre> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CloudClassificationSummary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.