示例#1
0
def create_amphora(params,param_name,username,password):    # Create new amphora for data
    credentials = Credentials(username=username, password=password)
    client = AmphoraDataRepositoryClient(credentials)    
    ## Create Amphora
    sep=" "
    amphora_description=sep.join(["Simulation of Pandemic code from Microprediction \n Parameter set is for",param_name," \n \
                                 N =",str(float(params['geometry']['n']))," \n I =",str(float(params['geometry']['i']))," \n \
                                 R =",str(float(params['geometry']['r']))," \n B =",str(float(params['geometry']['b']))," \n \
                                 H =",str(float(params['geometry']['h']))," \n C =",str(float(params['geometry']['c']))," \n \
                                 S =",str(float(params['geometry']['s']))," \n E =",str(float(params['geometry']['e']))," \n \
                                 P =",str(float(params['geometry']['p']))," \n T =",str(float(params['motion']['t']))," \n \
                                 K =",str(float(params['motion']['k']))," \n W =",str(float(params['motion']['w']))," \n \
                                 VI =",str(float(params['health']['vi']))," \n IS =",str(float(params['health']['is']))," \n \
                                 IP =",str(float(params['health']['ip']))," \n SP =",str(float(params['health']['sp']))," \n \
                                 IR =",str(float(params['health']['ir']))," \n ID =",str(float(params['health']['id']))," \n \
                                 SR =",str(float(params['health']['sr']))," \n SD =",str(float(params['health']['sd']))," \n \
                                 PD =",str(float(params['health']['pd']))," \n PR =",str(float(params['health']['pr']))])
    
    amphora_tnc="Creative_Commons_0"
    amphora_name=sep.join(["Ensemble simulation of Microprediction Pandemic for",param_name])
    labels=['Covid,simulation,timeseries',param_name]
    amphora = client.create_amphora(name = amphora_name, price = 0, description = amphora_description, terms_and_conditions_id = amphora_tnc, labels=labels)
    amphora_id = amphora.amphora_id
    
    # Create signals
    amphora.create_signal("vulnerable", attributes={"units":"#"})
    amphora.create_signal("infected", attributes={"units":"#"})
    amphora.create_signal("symptomatic", attributes={"units":"#"})
    amphora.create_signal("positive", attributes={"units":"#"})
    amphora.create_signal("recovered", attributes={"units":"#"})
    amphora.create_signal("deceased", attributes={"units":"#"})
    
    return amphora_id
示例#2
0
def amphora_callback(day, day_fraction, home, work, positions, status, params,
                     step_no, plot_hourly, plt):

    current_time = day + day_fraction
    if abs(current_time % 1) < 0.002:
        # Login to amphoradata.com
        try:
            username = os.getenv('amphora_username')
            password = os.getenv('amphora_password')
            credentials = Credentials(username, password)
            client = AmphoraDataRepositoryClient(credentials)
        except:
            print(
                "Couldn't login. Please sign up at amphoradata.com/regsiter if you need a free account."
            )

        # Check if amphora exists
        amphora_id = os.environ["amphora_id"]
        if amphora_id == None:
            param_name = "HOMESICK"
            amphora_id = create_amphora(params, param_name, username, password)

        # Push file (end of each day)
        print(current_time)
        push_snapshot(positions, status, current_time, client, amphora_id)

        # Push signal (when infected go to 0)
        if (sum(s in [INFECTED] for s in status) == 0):
            push_summary_timeseries(data, column_names, client, amphora_id)
示例#3
0
from datetime import datetime, timedelta

from amphora.client import AmphoraDataRepositoryClient, Credentials
import amphora_api_client as a10a
from amphora_api_client.rest import ApiException
from amphora_api_client.configuration import Configuration
import csv
import urllib.request
import ast

country_codes = ["AUS","NZL","PNG","GBR","CAN","USA","CHN","FJI","IDN","IND"]
country_id_stor = []

# Set up connection to amphoradata.com
# provide your login credentials
credentials = Credentials(username=os.getenv('username'), password=os.getenv('password'))
# create a client for interacting with the public Amphora Data Repository
client = AmphoraDataRepositoryClient(credentials)

date_str = []

def importCsv(file):
    cnt = 0
    with open(file, newline='') as csvfile:
        data = csv.reader(csvfile, delimiter=',', quotechar='|')
        for row in data:
            if row:
                date_str.append(row)
                cnt += 1
        print(cnt)
示例#4
0
import time
import os
from datetime import datetime, timedelta

import amphora_api_client as a10a
from amphora_api_client.rest import ApiException
from amphora_api_client.configuration import Configuration

import json

from amphora.client import AmphoraDataRepositoryClient, Credentials

# provide your login credentials
credentials = Credentials(username=os.environ['username'],
                          password=os.environ['password'])
# create a client for interacting with the public Amphora Data Repository
client = AmphoraDataRepositoryClient(credentials)

# https://beta.amphoradata.com/Amphorae/Detail?id=57d6593f-1889-410a-b1fb-631b6f9c9c85
id = "57d6593f-1889-410a-b1fb-631b6f9c9c85"

try:
    amphora_api = a10a.AmphoraeApi(client.apiClient)
    print(f'Getting signals for: {amphora_api.amphorae_read(id).name}')
    signals = amphora_api.amphorae_signals_get_signals(id)
    properties = list((s._property for s in signals))

    ts_api = a10a.TimeSeriesApi(
        client.apiClient)  # the API for interacting with time series
    tomorrow = datetime.now() + timedelta(hours=24)
    # Create a DateTimeRange to describe over what period we want data.
示例#5
0
import os
import getpass
from amphora.client import AmphoraDataRepositoryClient, Credentials
from amphora_api_client import ApplicationsApi, CreateApplication, AppLocation, UpdateApplication

username = input("Enter your Amphora username:"******"Enter your Amphora application Id:")
origin = input("Enter your deployed host/ CORS origin:")
redirect_path = input(
    "Enter the redirect path (default: /#/callback):") or "/#/callback"

new_location = AppLocation(origin=origin,
                           allowed_redirect_paths=[redirect_path])

application = appApi.applications_read_application(appId)
print(f'Found existing application: {application.name}')
locations = application.locations
locations.append(new_location)

update = UpdateApplication(name=application.name,
                           logout_url=application.logout_url,
                           id=application.id,
                           locations=locations)
appApi.applications_update_application(appId, update)
示例#6
0
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 10:50:19 2020

@author: Isaac
"""

# Import modules
from amphora.client import AmphoraDataRepositoryClient, Credentials
import os

# Login to amphora
amphora_username = os.getenv('username')
amphora_password = os.getenv('password')
credentials = Credentials(username=amphora_username, password=amphora_password)
client = AmphoraDataRepositoryClient(credentials)

# Get amphora id
amphora_id = "29ae56f6-cd0d-4e20-b6d2-9acf8fbf2495"

# Share amphora
amphora = client.get_amphora(amphora_id)
amphora.share_with("*****@*****.**")
示例#7
0
from amphora.client import AmphoraClient, Credentials

credentials = Credentials("*****@*****.**", "Password1!")
client = AmphoraClient(credentials)
amphora_id = "1227a860-0571-4542-942f-dd36cc13f810"
me = client.get_self()
print(me)

amphora = client.get_amphora(amphora_id)
print(amphora.metadata)
files = amphora.get_files()
print(files)
amphora_file = amphora.get_file("Nola.png")
attr = amphora_file.get_attributes()
# amphora_file.download("trst.png") // bug
import os
from amphora.client import AmphoraDataRepositoryClient, Credentials

NEW_FILE_NAME = "a_new_file.jpg"

# provide your login credentials
credentials = Credentials(username=os.environ['username'],
                          password=os.environ['password'],
                          host="https://app.amphoradata.com")
# create a client for interacting with the public Amphora Data Repository
client = AmphoraDataRepositoryClient(credentials)

# get a reference to an Amphora
amphora = client.create_amphora(
    name="Various Dogs",
    description="Contains labelled images of various types of dog breeds.")

# pushes the dog images to the Amphora Data Repository, with attributes
amphora.push_file("data/dogs/chihuahua.jpg",
                  attributes={
                      'breed': 'chihuahua',
                      'size': 'small',
                      'primaryColour': 'brown'
                  })
amphora.push_file("data/dogs/german-shepherd.jpg",
                  attributes={
                      'breed': 'german-shepherd',
                      'size': 'large',
                      'primaryColour': 'brown'
                  })
amphora.push_file("data/dogs/golden-retriever.jpg",
示例#9
0
import os
from datetime import datetime, timedelta

## Set up log metrics
start = time.time()
sep = '_'
experimentId = 0
mlflow.set_tracking_uri("your_mlflow_address")
runName = sep.join(['Job_at', str(datetime.utcnow())])
#mlflow.start_run(experiment_id=experimentId, run_name =runName)
mlflow.log_metric("time_to_complete", 0)
mlflow.log_metric("amphoras_uploaded", 0)
mlflow.log_metric("run_complete", 0)

# Set up connection to amphoradata.com
credentials = Credentials(username=os.getenv(username),
                          password=os.getenv(password))
client = AmphoraDataRepositoryClient(credentials)

cnt = 0
for i in range(Some_number):

    # Get the amphora you want to push data to
    amphora = client.get_amphora(Amphora_id)

    # Connect to original data source
    # Add code/module as needed

    # Do analytics/transforms on data
    # Add code/module as needed

    # Push to Amphora