Skip to content

Commit

Permalink
Add school challenge type, without additional taxa
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkohei13 committed Jul 23, 2024
1 parent 9e9920b commit ec1f36a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 46 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ Note that in order to create MariaDB database on Rahti, PHPMyAdmin data dump doe
- Setting up new challenge
- Provide list of basic taxa to `app/data/`, e.g. `plantae_2024.json` or use one of the existing ones.
- Provide list of all allowed taxa to `app/data/` (for backend) and `static/taxa/` (for frontend autocomplete), e.g. `plantae_2024_all.json`. This must contain all taxa that the basic list above contains, icnluding non-species.
- Challenge has field for autocomplete-parameters, but these are not currently used. Instead autocomplete uses static file as described above. This is to
- Challenges-table has field for autocomplete-parameters, but these are not currently used. Instead autocomplete uses static file as described above. This is to
- Make it faster than API calls (nearly instantaneous)
- Allow more flexibility, e.g. having only few higher taxa in addition to species
- The UI prevents setting dates that are outside the challenge dates, and dates in the future. This relies on min & max attributes on the date field and browser validation and error messages, and has limitations based on browser.
- If a challenge for 2025 is published in 2024, users have to clear dates which they might have added by clicking the species name (i.e. dates that are in 2024). Better solution would be to edit the Javascript so that it wont add today's date if it's outside the allowed range.
- TODO: If a challenge for 2025 is published in 2024, users have to clear dates which they might have added by clicking the species name (i.e. dates that are in 2024). Better solution would be to edit the Javascript so that it wont add today's date if it's outside the allowed range.
- When challenge is in draft or closed state, editing it still needs to be possible, e.g. to anonymize or trash it. Therefore only editing species list is disabled by setting the date fields disabled, and not enabling Javascript to change them either.

#### Future: To have a new challenge type, you would need to:
Expand Down Expand Up @@ -103,8 +103,6 @@ Note that in order to create MariaDB database on Rahti, PHPMyAdmin data dump doe
- Handling higher taxa (is uses adds rikkavoikukka, don't add voikukat to taxon_count)
- Accessibility
- Challenge sort order (int) for the front page - larger number shown on top
- School challenge:
- No additional taxa (setting to challenge, modify form)
- Later / nice:
- Move login_url, api_url, target id yms. konfiguraatiotiedostoon
- Own data dump download
Expand Down
86 changes: 48 additions & 38 deletions app/controllers/participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,46 +100,56 @@ def make_taxa_html(challenge, taxa_dates_json = None):
del taxa_dates[taxon_id]


# 2) Loop remaining taxa_dates, i.e. the additional taxa user has observed
# 2) If standard challenge, loop remaining taxa_dates, i.e. the additional taxa user has observed

# If taxa_dates is empty, set message text
if not taxa_dates:
additional_taxa_html = "<li class='no_additional_taxa'>Ei peruslistan ulkopuolisia lajeja.</li>\n"
if "challenge100" == challenge["type"]:
# If taxa_dates is empty, set message text
if not taxa_dates:
additional_taxa_html = "<li class='no_additional_taxa'>Ei peruslistan ulkopuolisia lajeja.</li>\n"
else:
additional_taxa_html = ""
print(taxa_dates)

for observed_taxon_id, observed_taxon_date in taxa_dates.items():

# Add to additional_taxa_html
# Check if taxon exists in all_taxa_names. Might not if
# A) It has been added to Laji.fi after the taxon list on this app has been set up (if using API for autocomplete)
# B) basic and all taxon files are not in sync (if using files for autocomplete)
fin = "" # default
swe = "" # default
sci = observed_taxon_id # default
if observed_taxon_id in all_taxa_names:
sci = all_taxa_names[observed_taxon_id]["sci"]

# Finnish name might not exist
if "fin" in all_taxa_names[observed_taxon_id]:
fin = all_taxa_names[observed_taxon_id]["fin"]

# Swedish name might not exist
if "swe" in all_taxa_names[observed_taxon_id]:
swe = all_taxa_names[observed_taxon_id]["swe"]

additional_taxa_html += make_species_html(observed_taxon_id, fin, swe, sci, min_date, max_date, observed_taxon_date)

# Combine into a list
html = f"""
<ul id='taxa'>\n
<li class='list_heading_3'><h3>Peruslistan ulkopuoliset lajit:</h3></li>\n
{ additional_taxa_html }
<li class='list_heading_3'><h3>Peruslistan lajit:</h3></li>\n
{ basic_taxa_html }
</ul>\n
"""
else:
additional_taxa_html = ""
print(taxa_dates)

for observed_taxon_id, observed_taxon_date in taxa_dates.items():

# Add to additional_taxa_html
# Check if taxon exists in all_taxa_names. Might not if
# A) It has been added to Laji.fi after the taxon list on this app has been set up (if using API for autocomplete)
# B) basic and all taxon files are not in sync (if using files for autocomplete)
fin = "" # default
swe = "" # default
sci = observed_taxon_id # default
if observed_taxon_id in all_taxa_names:
sci = all_taxa_names[observed_taxon_id]["sci"]

# Finnish name might not exist
if "fin" in all_taxa_names[observed_taxon_id]:
fin = all_taxa_names[observed_taxon_id]["fin"]

# Swedish name might not exist
if "swe" in all_taxa_names[observed_taxon_id]:
swe = all_taxa_names[observed_taxon_id]["swe"]

additional_taxa_html += make_species_html(observed_taxon_id, fin, swe, sci, min_date, max_date, observed_taxon_date)
# Combine into a list
html = f"""
<ul id='taxa'>\n
<li class='list_heading_3'><h3>Lajit:</h3></li>\n
{ basic_taxa_html }
</ul>\n
"""

# Combine into a list
html = f"""
<ul id='taxa'>\n
<li class='list_heading_3'><h3>Peruslistan ulkopuoliset lajit:</h3></li>\n
{ additional_taxa_html }
<li class='list_heading_3'><h3>Peruslistan lajit:</h3></li>\n
{ basic_taxa_html }
</ul>\n
"""

return html

Expand Down Expand Up @@ -322,6 +332,7 @@ def main(challenge_id_untrusted, participation_id_untrusted, form_data = None):

# Get challenge data to see that it exists and if it is draft/open/closed.
challenge = get_challenge(challenge_id)
print(challenge)

# CASE X: Challenge cannot be found or participation is closed
if not challenge:
Expand All @@ -330,7 +341,6 @@ def main(challenge_id_untrusted, participation_id_untrusted, form_data = None):
return {"redirect": True, "url": "/"}

html["challenge"] = challenge
print(challenge)

# Case A: User opened an empty form for submitting a new participation.
if not participation_id and not form_data:
Expand Down
8 changes: 7 additions & 1 deletion app/data/challenge_vocabulary.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
{
"key": "challenge100",
"label": {
"fi": "100 lajia -haaste"
"fi": "Yleinen 100 lajia -haaste"
}
},
{
"key": "school100",
"label": {
"fi": "Koulujen 100 lajia -haaste"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion app/data/data_models.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE `challenges` (
`taxon` varchar(16) NOT NULL, Taxon file identifier.
`date_begin` varchar(10) DEFAULT NULL,
`date_end` varchar(10) DEFAULT NULL,
`type` varchar(16) NOT NULL, Currently only one allowed value: challenge100.
`type` varchar(16) NOT NULL.
`title` varchar(255) NOT NULL, Name of the challenge.
`status` varchar(8) NOT NULL, Allowed values: draft, open, closed.
`description` varchar(2048) DEFAULT NULL,
Expand Down
9 changes: 7 additions & 2 deletions app/templates/form_challenge100.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@

{% block body %}

<!-- Challenge type: {{ html['challenge']['type'] }} -->

<!-- First check if participation exists and if 'trashed' key exists and equals 1 -->
{% if html.get('participation', {}).get('trashed') == 1 %}
<div class="info flash">Olet merkinnyt tämän osallistumisen poistetuksi, joten muut eivät näe sitä. (Voit palauttaa sen näkyville muuttamalla osallistumisen tilan julkiseksi ja tallentamalla.)</div>
Expand Down Expand Up @@ -261,7 +263,7 @@ <h1>Osallistuminen: {{ html['challenge']['title'] }}</h1>
</p>

<p>
<label for="place">Paikka (vapaaehtoinen): Haasteeseen osallistumisin tärkein havainnointipaikka, esim. kunta ja kylä. Haasteen havaintoja voi tehdä tämän paikan ulkopuolelta. Eri paikannimillä voit toteuttaa haastetta myös useammalta paikalta.</label><br>
<label for="place">Paikka (vapaaehtoinen): Haasteeseen osallistumisen tärkein havainnointipaikka, esim. kunta ja/tai paikannimi. Haasteen havaintoja voi tehdä myös tämän paikan ulkopuolelta. Voit halutessasi osallistua haasteeseen myös useammalta paikalta.</label><br>
<input
type="text"
id="place"
Expand All @@ -284,10 +286,13 @@ <h3 id="taxon_count_heading">{{ html['data_fields']['taxa_count'] }} lajia</h3>
{% endif %}
{% endif %}

<!-- If form is disabled, don't print this -->
<!-- Show instructions only if form is enabled -->
{% if html['disabled'] != 'disabled' %}
<p>Merkitse havaitsemillesi lajeille havaintopäivämäärä klikkaamalla lajinimeä tai päivämääräkenttää. (Poista havaintopäivämäärä klikkamalla ❌)</p>
{% endif %}

<!-- Show autocomplete only if form is enabled, and this is standard challenge -->
{% if html['disabled'] != 'disabled' and html['challenge']['type'] == 'challenge100' %}
<div id="autocomplete-container">
<label for="autocomplete-input"><h4>Hae lajia tai lisää listan ulkopuolisia lajeja:</h4></label>
<input type="text" id="autocomplete-input" placeholder="">
Expand Down

0 comments on commit ec1f36a

Please sign in to comment.