-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/calblueprint/ace-ny into 32…
…-continue-connecting-nyiso-and-nyserda
- Loading branch information
Showing
21 changed files
with
6,325 additions
and
137 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useState } from 'react'; | ||
import { useMap } from '@vis.gl/react-google-maps'; | ||
import ProjectModal from '@/components/ProjectModal'; | ||
import { Project } from '../../types/schema'; | ||
import { MarkerInfoWindow } from './MarkerInfoWindow'; | ||
|
||
export default function AddMarker({ | ||
projects, | ||
}: { | ||
projects: Project[] | null; | ||
}) { | ||
const [selectedProjectId, setSelectedProjectId] = useState<number | null>( | ||
null, | ||
); // track currently open modal | ||
const map = useMap(); | ||
|
||
const handleMarkerClick = ( | ||
projectId: number, | ||
position: { lat: number; lng: number }, | ||
) => { | ||
setSelectedProjectId(prevId => (prevId === projectId ? null : projectId)); // close modal if same, open if different | ||
map && map.panTo(position); // change center of map to selected marker | ||
}; | ||
|
||
const closeModal = () => { | ||
setSelectedProjectId(null); // close modal | ||
}; | ||
|
||
return ( | ||
<> | ||
{projects?.map((project: Project) => { | ||
return ( | ||
<MarkerInfoWindow | ||
key={project.id} | ||
position={{ | ||
lat: project.latitude, | ||
lng: project.longitude, | ||
}} | ||
projectName={project.project_name} | ||
projectDev={project.developer} | ||
projectId={project.id} | ||
onMarkerClick={handleMarkerClick} | ||
/> | ||
); | ||
})} | ||
|
||
{selectedProjectId && ( | ||
<ProjectModal | ||
project_id={selectedProjectId} | ||
closeModal={closeModal} | ||
openFirst={true} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
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,54 @@ | ||
import { useCallback, useState } from 'react'; | ||
import { | ||
AdvancedMarker, | ||
InfoWindow, | ||
useAdvancedMarkerRef, | ||
} from '@vis.gl/react-google-maps'; | ||
|
||
export const MarkerInfoWindow = ({ | ||
position, | ||
projectId, | ||
projectName, | ||
projectDev, | ||
onMarkerClick, | ||
}: { | ||
position: { lat: number; lng: number }; | ||
projectId: number; | ||
projectName: string; | ||
projectDev: string; | ||
onMarkerClick: ( | ||
projectId: number, | ||
position: { lat: number; lng: number }, | ||
) => void; | ||
}) => { | ||
const [markerRef, marker] = useAdvancedMarkerRef(); | ||
const [infoWindowShown, setInfoWindowShown] = useState(false); | ||
|
||
// clicking the marker will toggle the infowindow | ||
const handleMarkerEnter = useCallback( | ||
() => setInfoWindowShown(isShown => !isShown), | ||
[], | ||
); | ||
|
||
// if the maps api closes the infowindow, we have to synchronize our state | ||
const handleClose = useCallback(() => setInfoWindowShown(false), []); | ||
|
||
return ( | ||
<> | ||
<AdvancedMarker | ||
ref={markerRef} | ||
position={position} | ||
onMouseEnter={handleMarkerEnter} | ||
onMouseLeave={handleClose} | ||
onClick={() => onMarkerClick(projectId, position)} | ||
/> | ||
|
||
{infoWindowShown && ( | ||
<InfoWindow anchor={marker} onClose={handleClose} disableAutoPan={true}> | ||
<h2>{projectName}</h2> | ||
<p>Developer: {projectDev}</p> | ||
</InfoWindow> | ||
)} | ||
</> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
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,125 @@ | ||
import json | ||
import os | ||
from datetime import datetime | ||
from supabase import create_client, Client | ||
from geocodio import GeocodioClient | ||
|
||
from nyserda_scraper import query_nyserda_large, query_nyserda_solar | ||
from nyiso_scraper import query_nyiso | ||
|
||
renewable_energy_set = {'Hydroelectric', 'Land Based Wind', 'Offshore Wind', 'Solar', 'Geothermal', 'Energy Storage', 'Pumped Storage'} | ||
|
||
renewable_energy_map = { | ||
'H': 'Hydroelectric', | ||
'S': 'Solar', | ||
'ES': 'Energy Storage', | ||
'PS': 'Pumped Storage', | ||
'OSW': 'Offshore Wind', | ||
} | ||
|
||
url: str = os.environ.get("NEXT_PUBLIC_SUPABASE_URL") | ||
key: str = os.environ.get("NEXT_PUBLIC_SUPABASE_ANON_KEY") | ||
supabase: Client = create_client(url, key) | ||
|
||
geocode_api: str = os.environ.get("NEXT_PUBLIC_GEOCODIO_API_KEY") | ||
geocodio = GeocodioClient(geocode_api) | ||
|
||
def nyserda_large_to_database(): | ||
database = [] | ||
database.extend(query_nyserda_large()[0:10]) | ||
for project in database: | ||
if project.get('proposed_cod', None) is not None: | ||
ymd = datetime.strptime(project.get('proposed_cod'), '%Y').strftime('%Y-%m-%d') | ||
project['proposed_cod'] = ymd | ||
existing_project = supabase.table("Projects_duplicate").select("*").eq("project_name", project['project_name']).execute() | ||
if len(existing_project.data) > 0: | ||
try: | ||
response= supabase.table("Projects_duplicate").update(project).eq("project_name", project['project_name']).execute() | ||
print('UPDATE', response, '\n') | ||
except Exception as exception: | ||
print(exception) | ||
else: | ||
if (project.get('latitude', None) is not None) and (project.get('longitude', None) is not None): | ||
geocodio_result = geocodio.reverse((project.get('latitude'), project.get('longitude')), fields=['stateleg']).get('results', None) | ||
if geocodio_result is not None: | ||
location = geocodio_result[0] | ||
state_senate_district = int(location['fields']['state_legislative_districts']['senate'][0]['district_number']) | ||
assembly_district = int(location['fields']['state_legislative_districts']['house'][0]['district_number']) | ||
town = location['address_components']['city'] | ||
|
||
project['state_senate_district'] = state_senate_district | ||
project['assembly_district'] = assembly_district | ||
project['town'] = town | ||
try: | ||
response = supabase.table("Projects_duplicate").insert(project).execute() | ||
print('INSERT', response, '\n') | ||
except Exception as exception: | ||
print(exception) | ||
|
||
def nyserda_solar_to_database(): | ||
database = [] | ||
database.extend(query_nyserda_solar()) | ||
for project in database: | ||
if project.get('proposed_cod', None) is not None: | ||
ymd = datetime.fromisoformat(project.get('proposed_cod')).strftime('%Y-%m-%d') | ||
project['proposed_cod'] = ymd | ||
existing_project = supabase.table("Projects_duplicate").select("*").eq("project_name", project['project_name']).execute() | ||
if len(existing_project.data) > 0: | ||
try: | ||
response= supabase.table("Projects_duplicate").update(project).eq("project_name", project['project_name']).execute() | ||
print('UPDATE', response, '\n') | ||
except Exception as exception: | ||
print(exception) | ||
else: | ||
if (project.get('latitude', None) is not None) and (project.get('longitude', None) is not None): | ||
geocodio_result = geocodio.reverse((project.get('latitude'), project.get('longitude')), fields=['stateleg']).get('results', None) | ||
if geocodio_result is not None: | ||
location = geocodio_result[0] | ||
state_senate_district = int(location['fields']['state_legislative_districts']['senate'][0]['district_number']) | ||
assembly_district = int(location['fields']['state_legislative_districts']['house'][0]['district_number']) | ||
town = location['address_components']['city'] | ||
|
||
project['state_senate_district'] = state_senate_district | ||
project['assembly_district'] = assembly_district | ||
project['town'] = town | ||
try: | ||
response = supabase.table("Projects_duplicate").insert(project).execute() | ||
print('INSERT', response, '\n') | ||
except Exception as exception: | ||
print(exception) | ||
|
||
def nyiso_to_database(): | ||
database = [] | ||
database.extend(query_nyiso()) | ||
for project in database: | ||
if project.get('proposed_cod', None) is not None: | ||
try: | ||
ymd = datetime.strptime(project.get('proposed_cod'), '%m-%Y').strftime('%Y-%m-%d') | ||
except Exception as exception: | ||
ymd = datetime.strptime(project.get('proposed_cod'), '%m/%Y').strftime('%Y-%m-%d') | ||
except Exception as exception: | ||
print(exception) | ||
project['proposed_cod'] = ymd | ||
if project.get('renewable_energy_technology', None) in renewable_energy_map.keys(): | ||
project['renewable_energy_technology'] = renewable_energy_map[project.get('renewable_energy_technology')] # maps NYISO acronym to readable renewable energy tech | ||
existing_project = supabase.table("Projects_duplicate").select("*").eq("interconnection_queue_number", project['interconnection_queue_number']).execute() | ||
if len(existing_project.data) > 0: | ||
# TODO: define what fields we want to update | ||
try: | ||
response= supabase.table("Projects_duplicate").update(project).eq("interconnection_queue_number", project['interconnection_queue_number']).execute() | ||
print('UPDATE', response, '\n') | ||
except Exception as exception: | ||
print(exception) | ||
else: | ||
try: | ||
response = supabase.table("Projects_duplicate").insert(project).execute() | ||
print('INSERT', response, '\n') | ||
except Exception as exception: | ||
print(exception) | ||
|
||
''' | ||
For testing | ||
''' | ||
nyserda_large_to_database() | ||
# nyserda_solar_to_database() | ||
# nyiso_to_database() |
Oops, something went wrong.