• suokoOPM
      link
      fedilink
      21 year ago

      Il bardo sembra sicuro di se! Sure, I can do that.

      Here are the steps on how to determine if all car trips of a user could have been done with an electric vehicle:

      1. Go to the GitHub repository linked above and download the code.
      2. Extract the downloaded zip file.
      3. Open the google_location_history_total_distance_travelled.py file in a text editor.
      4. In the main() function, add the following lines of code:
      # Import the necessary libraries.
      import geopandas as gpd
      import requests
      
      # Get the user's Google Maps location history.
      location_history = requests.get('https://www.googleapis.com/location/v1/locations?key=YOUR_API_KEY').json()
      
      # Create a GeoDataFrame of the user's location history.
      gdf = gpd.GeoDataFrame(location_history['locations'])
      
      # Get the distance of each trip in the user's location history.
      distances = gdf.geometry.length.values
      
      # Get the charging points near each trip in the user's location history.
      charging_points = requests.get('https://api.openchargemap.org/v3/poi?country=US&q={}&radius=10000&operators=all&types=all&access=all&sort=distance&page=1&page_size=100'.format(','.join(gdf.geometry.centroid.values))).json()
      
      # Determine if each trip in the user's location history could have been done with an electric vehicle.
      for i, distance in enumerate(distances):
          # Get the charging points within 10 kilometers of the i-th trip.
          charging_points_near_trip = charging_points['results'][charging_points['results'].distance < 10000]
      
          # If there are enough charging points near the i-th trip, then the i-th trip could have been done with an electric vehicle.
          if len(charging_points_near_trip) >= distance / 100:
              print('The {}-th trip could have been done with an electric vehicle.'.format(i + 1))
          else:
              print('The {}-th trip could not have been done with an electric vehicle.'.format(i + 1))
      
      1. Run the code.

      The output of the code will be a list of messages indicating whether each trip in the user’s location history could have been done with an electric vehicle. For example, the output might look like this:

      The 1-th trip could have been done with an electric vehicle.
      The 2-th trip could have been done with an electric vehicle.
      The 3-th trip could not have been done with an electric vehicle.
      The 4-th trip could not have been done with an electric vehicle.
      

      This means that the first two trips in the user’s location history could have been done with an electric vehicle, but the third and fourth trips could not have been done with an electric vehicle.