# Size off the data chunk
size = 100000

##### Run Program

# Wait for the MySQL server to start
containerWait()

try:

    # Connect to MySQL and get cursor
    db_mysql, cur1 = connectMySQL(buffered=True)

    # Check timestamps
    if managementCompare('last_location_insert',
                         'last_predict_clusters',
                         cur=cur1,
                         db_mysql=db_mysql) or managementCompare(
                             'last_kmeans_model',
                             'last_predict_clusters',
                             cur=cur1,
                             db_mysql=db_mysql):

        # Get second cursor
        cur2 = db_mysql.cursor()

        # Load the kmeans model
        kmeanModel = pickle.load(open(path_model, 'rb'))

        ##### Get All Datapoints Tp Predict Clusters

        # Select statement
Exemplo n.º 2
0
# Path for the plot
path_model = 'build/KMeans_Model.p'

##### Run Program

# Wait for the MySQL server to start
containerWait()

try:

    # Connect to MySQL and get cursor
    db_mysql, cur = connectMySQL()

    # Check timestamps
    if managementCompare('last_predict_clusters',
                         'last_cluster_table',
                         cur=cur,
                         db_mysql=db_mysql):

        # Load the kmeans model
        kmeanModel = pickle.load(open(path_model, 'rb'))

        # Get the centers for the clusters
        kmeanCenters = kmeanModel.cluster_centers_

        ##### Map Clusters To Cities

        # Clusters to city names
        dict_cities = mapClustersToCities(kmeanCenters)

        # Create a dataframe for the cities
        df_cities = pd.DataFrame.from_dict(dict_cities, orient='index')
Exemplo n.º 3
0
# Chunk size for input to database
size = 100000

##### Run Program

# Wait for the MySQL server to start
containerWait()

try:

    # Connect to MySQL and get cursor
    db_mysql, cur = connectMySQL()

    # Check timestamps
    if managementCompare('last_cluster_table',
                         'last_rides_table',
                         cur=cur,
                         db_mysql=db_mysql):

        ##### Get The Point And City Dataframes

        # SQL query
        sql_query = 'SHOW columns FROM city_clusters'

        # Get column names
        cur.execute(sql_query)
        columns = [i[0] for i in cur.fetchall()]

        # SQL query
        sql_query = 'SELECT * FROM city_clusters'

        # Get dataframe
Exemplo n.º 4
0
# Wait for the MySQL server to start
containerWait()


try:

  # Connect to ZODB
  root = connectZEO()

  # Connect to MySQL and get cursor
  db_mysql, cur = connectMySQL()


  # Check timestamps
  if managementCompare('last_enrich_cluster_table', 'last_osm_download', cur=cur, db_mysql=db_mysql):


    ##### Iterate Over All Cities And Download OSM-Graph

    # SQL query
    sql_query = 'SELECT cluster_id FROM city_clusters WHERE city_analyse=1'

    # Execute the query
    cur.execute(sql_query)
    cluster_ids = cur.fetchall()

    # Iterate over all cities
    for cluster_id in cluster_ids:

      # Extract the data