Adds dead locations

This commit is contained in:
Nemo 2024-06-21 14:14:33 +05:30
parent 8d08fe1a81
commit a8e8d85e48
3 changed files with 226 additions and 6 deletions

139
_data/dead.json Normal file
View File

@ -0,0 +1,139 @@
[
"46ee4320-19a0-46e9-b7f0-2b6386f1f9d8",
"ea21710d-6e4a-4fa0-a581-dce21e7e9047",
"7f5c45ed-654b-4a6a-a99e-901170535051",
"2adfd6f7-612f-43c4-b0c8-17e790457334",
"ab7a565a-8cfd-4739-a334-ba083aeb268d",
"7ec2f7eb-90bb-4ad1-af7e-82915e4f5177",
"a8cbe2f0-d140-4cc2-a451-0d83cfd51920",
"7ae2cebf-2edb-41ac-b1f6-e924b1078eb6",
"62f68337-e57c-4435-a140-b2f0ddd567a9",
"56e3f9fc-9bf1-41d5-9ecd-ae89f4a8a8d5",
"3c62f1c9-9057-41b0-a58b-8a143a773031",
"1b32a1ab-4b99-42da-9380-6ba3f9fc2f72",
"383f0b3b-88a1-4e17-b9da-c1fa95714f18",
"66e390d3-aeee-40ac-a6ea-19a241b86299",
"e80afd71-2824-4265-90bf-7280163846cf",
"3c174c65-4b36-40fd-8f4f-ec03655f0e17",
"e94dfd6a-e936-44c0-b737-08c5aa7409fd",
"509cedd9-dbc6-4e03-a1c1-5ae9d8c211bc",
"00d1f4dd-b98b-4551-8bf5-d0db2eee1324",
"411663ab-6dc6-4bd3-9d60-bc47c321eb76",
"9f936294-40c8-4268-82d5-0206d096ded7",
"91c34875-4e42-448e-8b2a-536e87a90f35",
"d9fbe3ba-cc1e-4512-bdc6-c3a6951b9b8e",
"a65dbc68-aabf-4d03-910b-d8aa24d4b5ea",
"ea75155d-dc46-4bf3-b467-14913fb7d6af",
"56a6d454-594b-47df-81f8-820943b05637",
"2de5e80b-f2a8-495b-b1b5-e729bd8d820f",
"78ce001e-408b-47f5-a330-5a4c3673af8d",
"8694e685-1fb7-440c-bd49-775ed772f6c8",
"a3c92d16-76d9-403f-a52b-80b4e3603172",
"0168dfa0-b77f-411c-ba7c-9c8f73dd145e",
"8124dc38-abf4-4cb2-99d9-646e9ab6fb45",
"7f327fe4-50b9-4eaf-bee9-71fc14fbbcfd",
"ea41ef4e-e226-40ce-a3cd-a7a82572f99a",
"d72d7e01-ae2c-45e0-b2e0-93ab12b5b661",
"aea1af4b-e28a-4d3b-ada6-d6afb00ec3d8",
"44a67d3c-e67b-487f-8a8f-5576eb53d45f",
"2e28febb-09e2-475d-88fe-4d630bb78378",
"216fee70-b10b-4f36-9be3-9a971407425b",
"80753918-21d6-4ba2-9418-349d4ee8fe0b",
"a9a30ea4-66ba-49b0-b68f-a29606c4d9a4",
"332e5171-faf9-4db3-86ea-947b800de704",
"1635cc47-b8ae-4f23-ac05-0a5aef392d01",
"95758f46-9691-43fb-a9db-c2b12a6ac968",
"8522abb1-2e63-4831-89bb-725438f49167",
"7eebc047-843a-47a1-88e9-fb015a1981ee",
"077fff92-5e56-4383-8f80-17d4834c7000",
"7ee7e186-bb0a-4d52-be04-4c86179cd07f",
"48b3dda1-a5c9-4f5e-b1b5-056a191fe17a",
"3ba85d20-76ae-4499-914f-11ce6fc230c7",
"1a574f97-c304-49b0-9f04-4d2719e86812",
"2e76c70c-5b3a-4028-ad40-2b14fe447474",
"d6615827-1aac-49c0-92bd-f48263e38afa",
"a3687abb-83fe-4443-9a07-45115878b23d",
"802e949d-0245-410e-a85f-de03bf1eafa7",
"86fea0db-c2bd-4d7f-bc5c-af1949b769cb",
"002fda29-bf8e-4784-ba4b-a227f026bbc0",
"491ec3e6-813e-4df3-84df-59d2334df7bb",
"85bd455e-325b-49cc-934a-c77d77c58910",
"0cb0d356-47b0-4216-9127-049cfcf6691d",
"8d56e90e-4f54-46b3-bada-c6e5037aa99c",
"31dfc2e1-4dea-4ef2-a418-651f46ef1d21",
"707f71ca-1cd2-43f1-9296-2b5d0ad21ae1",
"ee0dae64-e2a5-48d2-a5e4-8acbd635e9d2",
"54066724-7400-4896-81f6-59667f63197a",
"b3ec9ba7-1664-45f1-8dc9-45001c8b0742",
"4f87854e-49f1-42df-861c-76b23fbe24fc",
"74c5bb2d-34b1-4087-adc0-1b1e70dde83b",
"3a4d14f3-2fe1-4214-8adf-4b63c9cef3f7",
"c7056d62-dfe7-483d-9366-18a510a8c83d",
"510d4f95-1b93-4261-ab95-7b009ed32b16",
"1dca0ee4-a78a-4ee2-adbd-0062c78d7e01",
"637873ea-8a9c-4ecb-b053-2131f4ab2765",
"829301f4-8d9d-4d15-9b0a-3c6bf068b21f",
"f39c2b75-c316-4cdc-850c-7a10eab9919b",
"a71c2a55-6e24-444a-b207-6050b44630b6",
"d4a8c2c9-e56e-466f-a5ba-357e5573572d",
"96a74ba9-46b7-4cef-8c1c-c407302361c6",
"70030e1e-00cc-479d-9efb-bbdf41ecf279",
"49217862-0ca7-40eb-88d3-1c031911cd20",
"9f4bfc2a-1351-4c4e-9c47-70766d641899",
"5d3c180e-0008-4bb1-a91e-9774a2aa5068",
"7e6843bc-9e33-4533-b47a-112e9726770a",
"bde0c46b-381c-42dc-8b7f-838e1bb462f4",
"44253ed2-21a7-48cf-b901-fb008421a447",
"c1e203d1-6673-4980-aeed-fa7358eecf8f",
"f5413dc8-0fd0-40c5-93e2-fa95e3632f48",
"62e2e799-a486-47c2-93f1-7f8404c2f7a0",
"aac064e2-0932-41af-ab27-f1ea77f20ca7",
"4d75c850-e1c5-414e-89b2-a6d7279f7bc0",
"1a840731-3ec9-40d2-b930-7af65e626ade",
"9c148ef2-44e7-46d8-9c7e-5110cdb46be7",
"8d1380d2-b595-4ddb-9b69-6e43027e6fe5",
"c092f16e-37b2-41ef-9775-2320ad0e943e",
"6c61202c-435f-4bb7-90ca-107088e343de",
"fa29e7ed-1d2e-4bb4-be9b-28d8c51e7da3",
"aa842dea-edde-4d3d-bd9d-e1cc7a1d5423",
"88e8447e-2771-4114-b52b-3ee8d56401ac",
"d0d9b131-dcc5-4718-bf9c-f98e5f9d03ba",
"7364bac9-56a9-49a3-82f6-dc012c61f949",
"caa49a8b-23a7-4cf5-8887-978356637ee9",
"e8f731c3-facd-49ec-9638-e73e3719bba8",
"8397cb84-6541-4198-9e6b-3e87a5ad2c5c",
"87ff524e-50f4-4c47-b844-b75fa6cf7381",
"3569e0a6-7fd4-4f2a-aa0b-d32478f369d4",
"b0cbc57b-b217-4e96-9b79-0c06c7473afe",
"33275efe-b9d4-4ce8-8fe0-3a0cee611f95",
"1748b536-ec79-4779-bb21-8ab1f9864fc3",
"7a9195c3-ce5c-4861-acf9-bbceaaec2ef4",
"1b07b26b-27f7-4194-9b8d-34104528e0d5",
"fd5be9b0-cd5c-4bf9-a013-88d308b3b586",
"bc9b1120-eadd-43fd-b515-80d7a3f4f5b0",
"91819ba6-b607-42c0-950f-5d1b3cdb463d",
"794265ac-cf15-47d6-80c4-5e9fac80c581",
"c85c1940-e229-4282-82ea-3272da31c02f",
"9fdc02fc-2ece-4445-bc1f-c60a37aa56be",
"cc16a77b-e392-482b-bb51-a99f8a612598",
"0fd71c42-7e44-40af-9252-0a36b72ed4a9",
"6491a697-e5da-4cc9-9aad-4cef2f16e4e4",
"9703ad2e-a52a-4952-b744-bad77207193d",
"4414be04-4f59-492b-a6e0-a4ac892daee3",
"32733bf1-44c6-47e5-81f2-5a920c8fcef4",
"18800db5-097d-4230-992c-8850b17f8e86",
"0af7fdf6-92ac-48d8-99c8-f6a24790960f",
"d7a0c360-92b1-45ac-83d3-568efa936c87",
"26ffb9ca-9683-4914-b331-eb54c70974e4",
"e785dc47-40ef-485b-ac6d-6d505ad420c5",
"11d1ceca-4d34-4fb8-af9d-ce21d7a61ffe",
"b1640c18-8ba5-43fa-a365-a6cc098d5bb3",
"54582de8-bd00-4019-927d-a3e2b52a0fca",
"2283ea85-bfd5-480a-b05c-0a14c5b4e933",
"b49eef88-865a-4e17-8323-f92870abd99d",
"76eedc06-8972-4bbb-b513-45599d58d429",
"93f30e81-315f-4bb6-a84b-02ea21b1239c",
"74a6b1eb-d07b-4d0e-b210-9526a9d12b83",
"52158b39-4bd5-4dc6-8b66-07cd2e72b02e",
"6182c8d1-8c0e-4003-a5bc-319a72a58909"
]

View File

@ -1,6 +1,13 @@
---
layout: default
---
<style>
{% for id in site.data.dead %}tr[data-id="{{id}}"]{% if forloop.last %}{% else %},{% endif %}
{% endfor %} {
background-color: #f8d7da !important;
}
</style>
<details open>
<summary>Show Map</summary>
<div width="740px" height="300px" id="map">
@ -47,8 +54,9 @@ layout: default
<tbody>
{% assign locations = site.data.plugo|sort:'state' %}
{% assign total = 0 %}
{% for row in locations %}
<tr id="{{row.id}}">
<tr id="{{row.id}}" data-id="{{row.id}}">
<td>
{%comment%}
{% assign state_lower_case = row.state|downcase %}
@ -57,7 +65,9 @@ layout: default
{% include location.html data=row %}
</td>
<td>{{row.business}}</td>
<td>{{row.totalAvailablePowerbanks}}</td>
<td>{{row.totalAvailablePowerbanks}}
{% if site.data.dead contains row.id %}💀{%endif%}
</td>
{% if row.totalAvailablePowerbanks == 0 %}
{% assign zeroPowerBankLocations = zeroPowerBankLocations | plus:1 %}
{% endif %}
@ -73,12 +83,15 @@ layout: default
<ul>
<li>Total Available Powerbanks: {{total}}</li>
<li>Total Locations: {{locations|size}}</li>
<li>{{zeroPowerBankLocations}} locations with zero powerbanks</li>
<li>Last Updated: {{site.time | date: "%Y-%m-%d %H:%M" }} IST</li>
<li>This page is automatically updated 5 times a day, at roughly 0930, 1230, 1530, 1830, 2130 IST</li>
<li>The map is also available in <a href="map.geojson">GeoJSON Format</a>. You can also view the underlying data directly at <a href="http://geojson.io/#data=data:text/x-url,https://captnemo.in/plugo/map.geojson">geojson.io</a>.
<li>{{zeroPowerBankLocations}} locations with zero powerbanks</li>
<li>Last Updated: {{site.time | date: "%Y-%m-%d %H:%M" }} IST</li>
<li>This page is automatically updated 5 times a day, at roughly 0930, 1230, 1530, 1830, 2130 IST</li>
<li>The map is also available in <a href="map.geojson">GeoJSON Format</a>. You can also view the underlying data directly at <a href="http://geojson.io/#data=data:text/x-url,https://captnemo.in/plugo/map.geojson">geojson.io</a>.
<li>Total Dead Locations: {{site.data.dead | size }} (Locations with zero power banks for the last two weeks)</li>
</ul>
<li>There are {{site.data.dead | size}} locations that are dead. These are locations that have not been updated in the last 30 days.</li>
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.js" integrity="sha256-04C2SeXF6JtsrsX+sFnI+gFdm56VJdhW49hWm4m+0io=" crossorigin="anonymous"></script>
<script>

68
dead-locations.py Normal file
View File

@ -0,0 +1,68 @@
import pygit2
import os
import json
from datetime import datetime, timedelta
import msgspec
# Define the structure of the JSON data using msgspec
class PowerbankData(msgspec.Struct):
id: str
totalAvailablePowerbanks: int
# Function to check if a location has always had totalAvailablePowerbanks=0
def check_dead_location(commits, repo):
all_locations = set()
alive_locations = set()
for commit in commits:
try:
tree = commit.tree
if '_data/plugo.json' in tree:
blob = repo[tree['_data/plugo.json'].id]
file_content = blob.data.decode('utf-8')
data = msgspec.json.decode(file_content, type=list[PowerbankData])
for item in data:
location_id = item.id
total_powerbanks = item.totalAvailablePowerbanks
all_locations.add(location_id)
if location_id == "9a5c1751-9820-4102-9e0d-f84ab974031d":
print(item)
if total_powerbanks != 0:
alive_locations.add(location_id)
except KeyError:
pass
return all_locations - alive_locations
# Main function to iterate through commits and identify dead locations
def main():
# Open the repository
repo_path = '.' # Assuming the script is run from the root of the repository
repo = pygit2.Repository(repo_path)
# Determine the date range (last two weeks)
today = datetime.today()
two_weeks_ago = today - timedelta(weeks=2)
# Collect commits within the date range
commits = list(repo.walk(repo.head.target, pygit2.GIT_SORT_TOPOLOGICAL))
commits_within_range = [
commit for commit in commits
if datetime.fromtimestamp(commit.commit_time) >= two_weeks_ago
]
# Check for dead locations
dead_locations = check_dead_location(commits_within_range, repo)
# Write dead_locations to JSON file
output_file = '_data/dead.json'
with open(output_file, 'w') as f:
json.dump(list(dead_locations), f, indent=2)
print(f"Dead locations written to {output_file}")
if __name__ == "__main__":
main()