예제 #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 create_or_update_amphorae(client: AmphoraDataRepositoryClient, amphora_map,
                              location_info):

    new_map = dict()
    try:
        # client=amphora_client.ApiClient(configuration)
        # amphora_api = amphora_client.AmphoraeApi(client)

        for key in amphora_map:
            id = amphora_map[key]
            if (id == None):
                # we have to create an Amphora
                wzloc = location_info[key]
                locname = wzloc['name']
                print(f'Creating new Amphora for location {locname}')
                # create the details of the Amphora
                name = 'Weather: ' + wzloc['name'] + ' (' + wzloc['state'] + ')'
                desc = 'WeatherZone data, from ' + wzloc[
                    'name'] + '. WeatherZone code: ' + wzloc[
                        'code'] + ', PostCode: ' + wzloc['postcode']
                labels = 'Weather,forecast,timeseries'
                ts_cs_id = 'Weatherzone_Forecast'

                amphora = client.create_amphora(
                    name,
                    desc,
                    price=2,
                    labels=labels,
                    lat=wzloc['latitude'],
                    lon=wzloc['longitude'],
                    terms_and_conditions_id=ts_cs_id)

                # now create the signals
                print("Creating Signals")
                for s in signals():
                    amphora.create_signal(s._property, s.value_type,
                                          s.attributes)

                new_map[key] = amphora.id
            else:
                amphora = client.get_amphora(id)
                time.sleep(0.2)  # wait a bit to prevent hitting the rate limit
                print(f'Using existing amphora: {amphora.metadata.name}')
                new_map[key] = id

    except Exception as e:
        print("Error Create or update amphorae: %s\n" % e)
        raise e

    return new_map
예제 #3
0
def upload_signals_to_amphora(client: AmphoraDataRepositoryClient, wz_lc,
                              amphora_id):

    forecasts = load_forecasts(wz_user, wz_password, wz_lc)

    # TRANSFORM
    signals = []
    for f in forecasts:
        signals.append(
            dict(t=f['utc_time'],
                 temperature=f['temperature'],
                 description=f['icon_phrase'],
                 rainProb=f['rain_prob'],
                 windSpeed=f['wind_speed'],
                 windDirection=f['wind_direction'],
                 cloudCover=f['cloud_cover_percent'],
                 pressure=f['pressure'],
                 rainfallRate=f['rate']))

    try:
        amphora = client.get_amphora(amphora_id)
        print(
            f'Uploading signals to {amphora.metadata.name} {amphora.metadata.id}'
        )
        print(f'Properties of first signal val: {signals[0].keys()}')
        amphora.push_signals_dict_array(
            signals)  # this sends the data to Amphora Data
        print(f'Sent {len(signals)} signals')

    except Exception as e:
        print("Exception: %s\n" % e)
        raise e
예제 #4
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)
예제 #5
0
def upload_MLA_signals(client: AmphoraDataRepositoryClient, signals_dict,
                       amphora_id):
    signals = []
    success_indicator = 0
    try:
        for key, value in signals_dict.items():
            s = {'t': key, 'price': float(value)}
            signals.append(s)

        amphora = client.get_amphora(amphora_id)
        if len(signals) > 1:
            print(
                f'Uploading signals to {amphora.metadata.name} {amphora.metadata.id}'
            )
            print(f'Properties of first signal val: {signals[0].keys()}')
            amphora.push_signals_dict_array(
                signals)  # this sends the data to Amphora Data
            print(f'Sent {len(signals)} signals')
        else:
            print(f'0 signals for {amphora.metadata.name}')

    except Exception as e:
        print("Exception: %s\n" % e)
        success_indicator = 0
        raise e
    return success_indicator
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 non-Amphora librarys
from array import array
import os
import numpy as np
import time
from datetime import datetime, timedelta

# Login to amphoradata.com
credentials = Credentials(username=os.getenv('username'),
                          password=os.getenv('password'))
client = AmphoraDataRepositoryClient(credentials)
amphora_api = a10a.AmphoraeApi(client.apiClient)


# Define model function
def time_product(date_time):
    time_hour = date_time.hour
    time_minute = date_time.minute
    time_second = date_time.second

    time_prod = time_hour * time_minute * time_second

    return time_prod


#####################################
예제 #7
0
Created on Mon Apr  6 17:48:07 2020
@author: Isaac
"""

# Import Amphora librarys
from amphora.client import AmphoraDataRepositoryClient, Credentials

# Import non-Amphora librarys
import os
from datetime import datetime, timedelta
import matplotlib.pyplot as plt

# Login to amphoradata.com
credentials = Credentials(username=os.getenv('username'),
                          password=os.getenv('password'))
client = AmphoraDataRepositoryClient(credentials)

# Get Amphora of interest
f = open("Amphora_id.txt", "r")
amphora_id = f.read()

# Set time points of interest
start = datetime.utcnow() + timedelta(hours=-48)
end = datetime.utcnow()
dt_range = DateTimeRange(_from=start, to=end)

# Pull data from Amphora
amphora = client.get_amphora(amphora_id)
signals = amphora.get_signals()
df = signals.pull(date_time_range=dt_range).to_pandas(t_as_index=False)
    y_oi = 100000
    for n in range(N):
        if abs(y[n] - p) < y_oi:
            y_oi = abs(y[n] - p)
            x_oi = x[n]

    print(x_oi)
    print(y_oi)
    return x_oi


##############################################################
# parameters and details
credentials = Credentials(username=os.getenv('username'),
                          password=os.getenv('password'))
client = AmphoraDataRepositoryClient(credentials)

Electricity_Amphora_id = '89c2e30d-78c8-46ef-b591-140edd84ddb6'
Weather_Amphora_id = '2866d34f-fe2b-4c07-acdd-28fe2d6d9194'
Forecast_amphora_id = '78831a6b-de49-454e-9e5c-7c757478e783'
name = 'South_Australia_Electricity_Price.json'

#############################################################
# Publish raw data on microprediction
mw = MicroWriter(write_key="bdfd44affd28e6c5b45329d6d4df7729")
time_range = a10a.DateTimeRange(_from=datetime.utcnow() + timedelta(hours=-1),
                                to=datetime.utcnow())
electricity_amphora = client.get_amphora(Electricity_Amphora_id)
electricity_signals = electricity_amphora.get_signals()
df = electricity_signals.pull(date_time_range=time_range).to_pandas()
price = df['price']
예제 #9
0
import os
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)

# scope can be self or organisation
# access type can be created or purchased
amphoras = client.list_amphora(scope='self',
                               access_type='purchased',
                               take=5,
                               skip=0)

print(amphoras)
예제 #10
0
import os
from datetime import datetime, timedelta
from amphora.client import AmphoraDataRepositoryClient, Credentials
from amphora_api_client import DateTimeRange

# 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)

# get a reference to an Amphora
amphora = client.get_amphora("57d6593f-1889-410a-b1fb-631b6f9c9c85")

# get a reference to the Amphora's signals
signals = amphora.get_signals()

# download some signals and convert to a pandas dataframe

dt_range = DateTimeRange(_from=datetime.utcnow() + timedelta(days=-1),
                         to=datetime.utcnow() + timedelta(days=2))
df = signals.pull(date_time_range=dt_range,
                  include_wt=True,
                  tsi_api="GetEvents").to_pandas()

print(df.describe())
temp = df['temperature']
print(f'Maximum temperature: {temp.max()}')
# update a signal
temperature_signal = signals['temperature']
예제 #11
0
def create_amphora(client: AmphoraDataRepositoryClient, site: BOMSite)-> Amphora:
    return client.create_amphora(f'Weather Observations: {site.name}, {site.state}', des(site),
        price=PRICE, lat=site.lat, lon=site.lon, terms_and_conditions_id=TERMS_ID, labels=labels )
예제 #12
0
import os
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)

results = client.search_amphora(term='Fridley Creek',
                                labels='waterquality',
                                take=5)

print(results.count)
print(
    f'There are {results.count} search results, and {len(results.items)} in items list'
)
if results.count > 0:
    print(results.items[0])
예제 #13
0
import os
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)
# get information about the logged in user
my_information = client.get_self()
print(my_information)

# {'about': "I'm the CTO at Amphora Data.",
#  'email': None,
#  'full_name': 'Rian Finnegan',
#  'id': 'd54505c0-2756-44e6-8b99-e7fb0fbc8711',
#  'last_modified': datetime.datetime(2020, 3, 23, 0, 3, 54, 922250, tzinfo=tzutc()),
#  'organisation_id': '7b429e6c-2885-49cf-994d-4775ae170d64',
#  'user_name': '*****@*****.**'}
예제 #14
0
import os
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)

# create an amphora
amphora = client.create_amphora("My New Data Store",
                                "This is a description of my new Amphora",
                                lat=20,
                                lon=20)
print(amphora.metadata)
# update the amphora
amphora.update(price=10, labels=["custom", "labels"])
# delete the amphora
amphora.delete()
예제 #15
0
import os
from amphora.client import AmphoraDataRepositoryClient, Credentials

# 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.get_amphora("84f36667-9bc9-4da1-baba-1ef3160eae0f")

# skip = number of files to ignore
# take= the max num of files in the list
# order_by = the way to order the files. Choose Alphabetical (default) or LastModified
files = amphora.get_files(100, 0)

print(f'The client returned a list with {len(files)} names')
print(f'The first file name is {files[0].name}')

# download a file
for f in files:
    print(f'Downloading {f.name}')
    f.pull(f'./data/temp/{f.name}')

print('done')
예제 #16
0
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",
예제 #17
0
# Import Amphora modules
from amphora.client import AmphoraDataRepositoryClient, Credentials

# Import non-Amphora modules
import os

# Login to amphoradata.com
credentials = Credentials(username=os.getenv('username'),
                          password=os.getenv('password'))
client = AmphoraDataRepositoryClient(credentials)

# Set metadata for Amphora
name = "Amphora_Name"  #Name the amphora as string
description = "Amphora_Description"  #Describe the amphora as string
price = 0  #Monthly price as float
labels = ["Label_1", "Label_2", "Label_3"]  #List of 2-5 one word strings
lat = 0.0  #Enter latitude as float
lon = 0.0  #Enter longitude as float

# Create Amphora
amphora = client.create_amphora(name=name,
                                description=description,
                                labels=labels,
                                price=price,
                                lat=lat,
                                lon=lon)
예제 #18
0
import os
from amphora_api_client import Quality
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)

# get a reference to an Amphora
amphora = client.get_amphora("e48c9a35-4696-406c-a963-8e72a8bf0131")

quality = Quality()  # Quality | The data quality metrics.
quality.accuracy = 2

res = client.amphoraeApi.amphora_quality_set(amphora.amphora_id, quality)
print(res)
예제 #19
0
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)

importCsv("dates_of_interest.csv")
예제 #20
0
import os
from datetime import datetime, timedelta
import pytz
import constants
from amphora.client import AmphoraDataRepositoryClient, Credentials
from amphora_api_client import DateTimeRange
from pandas import DataFrame

# login
username = os.getenv('username')
password = os.getenv('password')
credentials = Credentials(username, password)
client = AmphoraDataRepositoryClient(credentials)

insights = client.get_amphora(constants.insights_id)


# save alert method
def alert(name: str, text: str):
    # create the file locally
    filepath = f'{name}.txt'
    file_object = open(filepath, "w+")
    file_object.write(text)
    file_object.flush()
    file_object.close()
    insights.push_file(filepath, f'{name}')
    print(f'Uploaded file {name}')


def check_max_and_alert(df: DataFrame, key: str, threshold: int,
                        file_prefix: str, message: str):
예제 #21
0
import os
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)

# get a reference to an Amphora
amphora = client.create_amphora(name="Access Controls Example",
                                description="Used for showing Access Controls")

amphora.share_with(
    "*****@*****.**")  # the username of the person to share with
예제 #22
0
from datetime import datetime
from amphora.client import AmphoraDataRepositoryClient, Credentials

logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger()

import extract
import bom
import idcache
import signals
import operations as op

# 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)


sites = extract.load_wmo_sites()

amphora_map = idcache.load()
max_t = None

# use a random amphora in the list to get the last written time.
# this should be more resilient to failure than always using the first.
if(len(amphora_map) > 0):
    random_amphora_id = random.choice(list(amphora_map.values()))
    random_amphora = client.get_amphora(random_amphora_id)
    max_t = op.get_max_t(random_amphora)
    logger.info(f'Max T is {max_t} from Amphora({random_amphora_id})')