Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix observations column ordering #75

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions andromeda-ui/components/ObservationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Image from 'next/image'
interface ObservationTableProps {
iNatUser: string | undefined;
observations: any[];
observationFieldnames: string[];
totalObservations: number;
maxObs: number;
}
Expand All @@ -23,11 +24,11 @@ const KNOWN_COLUMNS = new Set([
]);

export default function ObservationTable(props: ObservationTableProps) {
const { observations, maxObs, iNatUser, totalObservations} = props;
const { observations, observationFieldnames, maxObs, iNatUser, totalObservations} = props;
const showing = Math.min(observations.length, maxObs);
let extraColumns: string[] = [];
if (observations.length > 0) {
extraColumns = Object.keys(observations[0]).filter((x) => !KNOWN_COLUMNS.has(x))
extraColumns = observationFieldnames.filter((x) => !KNOWN_COLUMNS.has(x))
}
const exampleObservations = observations.slice().slice(0, maxObs);
const rows = exampleObservations.map((x) => {
Expand Down
3 changes: 3 additions & 0 deletions andromeda-ui/pages/fetch-data/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function GeneratePage() {
const [fetching, setFetching] = useState<boolean>(false);
const [showObservations, setShowObservations] = useState<boolean>(false);
const [observations, setObservations] = useState<any[]>([]);
const [observationFieldnames, setObservationFieldnames] = useState<string[]>([]);
const [totalObservations, setTotalObservations] = useState<number>(0);
const [generateObservationDataset, setGenerateObservationDataset] = useState<boolean>(false);
const [observationsURL, setObservationsURL] = useState<string>();
Expand All @@ -58,6 +59,7 @@ export default function GeneratePage() {
try {
const result = await fetchObservations(iNatUser, addSatRGBData, addLandCover, SHOW_OBS_MAX);
setObservations(result.data);
setObservationFieldnames(result.fieldnames);
setTotalObservations(result.total);
setObservationsURL(undefined);
if (result.warnings.length) {
Expand Down Expand Up @@ -106,6 +108,7 @@ export default function GeneratePage() {
<ObservationTable
iNatUser={iNatUser}
observations={observations}
observationFieldnames={observationFieldnames}
totalObservations={totalObservations}
maxObs={SHOW_OBS_MAX} />
{warningNotice}
Expand Down
4 changes: 2 additions & 2 deletions andromeda/inaturalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def get_label(idx, total_observations, reversed):
def get_inaturalist_observations(user_id, add_sat_rgb_data, add_landcover_data, limit):
idx = 0
missing_lat_long = False
obeservation_ary, total_observations = get_observations(user_id=user_id, limit=limit)
observation_ary, total_observations = get_observations(user_id=user_id, limit=limit)
observations = Observations(fieldnames=CSV_FIELDS[:], total=total_observations)
for obs in obeservation_ary:
for obs in observation_ary:
observed_on = obs.get("observed_on")
if not observed_on:
raise BadObservationException(OBSERVED_ON_MISSING_MSG)
Expand Down
1 change: 1 addition & 0 deletions andromeda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def get_inaturalist(user_id):
"user_id": user_id,
"total": observations.total,
"data": observations.data,
"fieldnames": observations.fieldnames,
"warnings": list(observations.warnings)
})
elif format == "csv":
Expand Down
12 changes: 8 additions & 4 deletions andromeda/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ def test_inverse_dimensional_reduction(self, mock_dataset_store):
def test_get_inaturalist(self, mock_get_inaturalist_observations):
observations = [{"Image_Label": "p1"}]
warnings = ["missing_lat_long"]
fieldnames = ["Image_Label"]
mock_get_inaturalist_observations.return_value = Mock(
data=observations, warnings=warnings, total=1)
data=observations, fieldnames=fieldnames, warnings=warnings, total=1)
client = app.test_client()
result = client.get(f"/api/inaturalist/bob")
self.assertEqual(result.status_code, 200)
Expand All @@ -102,6 +103,7 @@ def test_get_inaturalist(self, mock_get_inaturalist_observations):
{
'total': 1,
"data": [{"Image_Label": "p1"}],
'fieldnames': ["Image_Label"],
"user_id": "bob",
"warnings": ["missing_lat_long"],
},
Expand All @@ -113,9 +115,10 @@ def test_get_inaturalist(self, mock_get_inaturalist_observations):
@patch("main.get_inaturalist_observations")
def test_get_inaturalist_limit(self, mock_get_inaturalist_observations):
observations = [{"Image_Label": "p1"}]
fieldnames = ["Image_Label"]
warnings = ["missing_lat_long"]
mock_get_inaturalist_observations.return_value = Mock(
data=observations, warnings=warnings, total=1)
data=observations, fieldnames=fieldnames, warnings=warnings, total=1)
client = app.test_client()
result = client.get(f"/api/inaturalist/bob?limit=6")
self.assertEqual(result.status_code, 200)
Expand All @@ -124,6 +127,7 @@ def test_get_inaturalist_limit(self, mock_get_inaturalist_observations):
{
'total': 1,
"data": [{"Image_Label": "p1"}],
'fieldnames': ['Image_Label'],
"user_id": "bob",
"warnings": ["missing_lat_long"],
},
Expand Down Expand Up @@ -176,7 +180,7 @@ def test_get_inaturalist_xml(self, mock_get_inaturalist_observations):

@patch("main.get_inaturalist_observations")
def test_get_inaturalist_add_rgb(self, mock_get_inaturalist_observations):
mock_get_inaturalist_observations.return_value = Mock(data=[], warnings=[], total=0)
mock_get_inaturalist_observations.return_value = Mock(data=[], fieldnames=[], warnings=[], total=0)
client = app.test_client()
result = client.get(f"/api/inaturalist/bob?format=json&add_sat_rgb_data=true")
self.assertEqual(result.status_code, 200)
Expand All @@ -185,7 +189,7 @@ def test_get_inaturalist_add_rgb(self, mock_get_inaturalist_observations):

@patch("main.get_inaturalist_observations")
def test_get_inaturalist_add_landcover(self, mock_get_inaturalist_observations):
mock_get_inaturalist_observations.return_value = Mock(data=[], warnings=[], total=0)
mock_get_inaturalist_observations.return_value = Mock(data=[], fieldnames=[], warnings=[], total=0)
client = app.test_client()
result = client.get(f"/api/inaturalist/bob?format=json&add_landcover_data=true")
self.assertEqual(result.status_code, 200)
Expand Down