示例#1
0
def run_speedtest(config):
    """
    Execute the speedtest, save the result and return the result
    """
    with LogPersistence(config['database']) as database:

        # Speedtest
        print "Starting measurement..."
        speed = test_speed()

        database.save(speed)
        print speed
    return speed
示例#2
0
def my_type_is(type):
    card_title = render_template('card_title')
    if type is not None:
        session.attributes[TYPE_KEY] = type
        with LogPersistence('speedtest.db') as persistence:
            response = persistence.fetch_last(type)
            if (type == "download" or type == "upload"):
                result = str(int(response[0] / 1048567)) + " Mbits/Sekunde"
            else:
                result = str(int(response[0]))
            speed_text = render_template('known_type',
                                         currentSpeed=result,
                                         type=type).encode('utf8')
            return statement(speed_text).simple_card(card_title, speed_text)
    else:
        question_text = render_template('unknown_type').encode('utf8')
        reprompt_text = render_template('unknown_type_reprompt').encode('utf8')
        return statement(question_text).reprompt(reprompt_text).simple_card(
            card_title, question_text)
示例#3
0
def my_type_is(type):
    """
    Get the last speedtest result
    """
    card_title = render_template('card_title')
    if type is not None:
        session.attributes[TYPE_KEY] = type
        with LogPersistence(CONFIG['database']) as persistence:
            response = persistence.fetch_last(type)
            print response
            if type == "download" or type == "upload":
                session.attributes[RESULT_KEY] = int(response[0] / BIT_DIVIDER)
                result = str(session.attributes[RESULT_KEY]) + SPEED_TYPE
            else:
                session.attributes[RESULT_KEY] = int(response[0])
                result = str(session.attributes[RESULT_KEY])

            twitter_enabled = CONFIG['twitter_enabled'] is not None and CONFIG['twitter_enabled']

            # Choose the template
            template = 'known_type_tweet' if twitter_enabled else 'known_type'
            speed_text = render_template(
                template,
                currentSpeed=result,
                type=type,
                measure_date=response[1].strftime('%Y%m%d'),
                measure_time=response[1].strftime('%H:%M')
            ).encode('utf8')

            if twitter_enabled:
                # If twitter is enabled, we ask a question instead of stating something
                speed_reprompt = render_template('known_type_repromt', type=type).encode('utf8')
                return question('<speak>{}</speak>'.format(speed_text)) \
                    .reprompt(speed_reprompt).simple_card(card_title, speed_text)

            return statement('<speak>{}</speak>'.format(speed_text)) \
                .simple_card(card_title, speed_text)
    else:
        question_text = render_template('unknown_type').encode('utf8')
        reprompt_text = render_template('unknown_type_reprompt').encode('utf8')
        return question(question_text).reprompt(reprompt_text)\
            .simple_card(card_title, question_text)
示例#4
0
def get_stats(type):
    """
    Get the Max, Min, Avg and Count of the given type of todays results
    """
    card_title = render_template('card_title')
    if type is not None:
        session.attributes[TYPE_KEY] = type
        print type
        with LogPersistence(CONFIG['database']) as persistence:
            response = persistence.fetch_stats(type)
            print response
            if type == "download" or type == "upload":
                speed_max = str(int(response[0] / BIT_DIVIDER)) + SPEED_TYPE
                speed_min = str(int(response[1] / BIT_DIVIDER)) + SPEED_TYPE
                speed_avg = str(int(response[2] / BIT_DIVIDER)) + SPEED_TYPE
                speed_count = response[3]
            else:
                speed_max = response[0]
                speed_min = response[1]
                speed_avg = response[2]
                speed_count = response[3]

            # Choose the template
            template = 'stats_text' if (type == 'download' or type == 'upload')\
                else 'stats_text_ping'
            speed_text = render_template(
                template,
                max=speed_max,
                min=speed_min,
                avg=speed_avg,
                count=speed_count,
                type=type
            ).encode('utf8')

            return statement('<speak>{}</speak>'.format(speed_text)) \
                .simple_card(card_title, speed_text)
    else:
        question_text = render_template('unknown_type').encode('utf8')
        reprompt_text = render_template('unknown_type_reprompt').encode('utf8')
        return question(question_text).reprompt(reprompt_text)\
            .simple_card(card_title, question_text)
示例#5
0
import numpy as np
from persistence import LogPersistence
import config

FILENAME = sys.argv[1]
DATA = np.genfromtxt(
    FILENAME,
    delimiter=',',
    skip_header=0,
    skip_footer=0,
    names=['date', 'time', 'zone', 'ping', 'download', 'upload'],
    dtype="S10,S5,S5,f8,f8,f8")

CONFIG = config.load_config()

with LogPersistence(CONFIG['database']) as persistence:
    for i in range(len(DATA['time'])):
        instance = {
            'measure_dt':
            datetime.strptime(DATA['date'][i] + ' ' + DATA['time'][i],
                              "%Y-%m-%d %H:%M"),
            'ping':
            DATA['ping'][i],
            'download':
            DATA['download'][i] * 1000000,
            'upload':
            DATA['upload'][i] * 1000000,
        }

        print instance
示例#6
0
from datetime import datetime
import sys
import numpy as np
from persistence import LogPersistence

FILENAME = sys.argv[1]
DATA = np.genfromtxt(
    FILENAME,
    delimiter=',',
    skip_header=0,
    skip_footer=0,
    names=['date', 'time', 'zone', 'ping', 'download', 'upload'],
    dtype="S10,S5,S5,f8,f8,f8")

with LogPersistence('speedtest.db') as persistence:
    for i in range(len(DATA['time'])):
        instance = {
            'measure_dt':
            datetime.strptime(DATA['date'][i] + ' ' + DATA['time'][i],
                              "%Y-%m-%d %H:%M"),
            'ping':
            DATA['ping'][i],
            'download':
            DATA['download'][i] * 1000000,
            'upload':
            DATA['upload'][i] * 1000000,
        }

        print instance