Example #1
0
    def test_value_timestamp(self):
        """
        Send value request to StatHat API with timestamp
        """
        responses.add(
            responses.POST,
            'http://stathatapi.example/ez',
            body='',
            status=200,
            content_type='application/json'
        )
        instance = StatHat('*****@*****.**')

        instance.value('a_stat', 'a_value', 10000)

        self.assertEqual(len(responses.calls), 1)
        self.assertDictEqual(
            json.loads(responses.calls[0].request.body),
            {
                'ezkey': '*****@*****.**',
                'data': [
                    {'stat': 'a_stat', 'value': 'a_value',  't': 10000}
                ]
            }
        )
def main():

    stathat = StatHat(STATHAT_KEY)

    payload = {"ezkey": STATHAT_KEY, "data": []}

    data = speedtest()

    stathat.value('Latency', data['latency'])
    stathat.value('Download', data['download'])
    stathat.value('Upload', data['upload'])

    print data
Example #3
0

# Loop over epochs.
lr = args.lr
prev_val_loss = None
for epoch in range(1, args.epochs + 1):
    epoch_start_time = time.time()
    train()
    val_loss = evaluate(val_data)
    print('-' * 89)
    print('| end of epoch {:3d} | time: {:5.2f}s | valid loss {:5.2f} | '
          'valid ppl {:8.2f}'.format(epoch, (time.time() - epoch_start_time),
                                     val_loss, math.exp(val_loss)))
    print('-' * 89)
    # Anneal the learning rate.
    stats.value('validated_loss', val_loss)
    if prev_val_loss and val_loss >= prev_val_loss:
        lr /= 4
    prev_val_loss = val_loss

    with open(args.save + str(epoch) + '.pt', 'wb') as f:
        torch.save(model, f)

# Run on test data and save the model.
test_loss = evaluate(test_data)
print('=' * 89)
print('| End of training | test loss {:5.2f} | test ppl {:8.2f}'.format(
    test_loss, math.exp(test_loss)))
print('=' * 89)
if args.save != '':
    with open(args.save + '.pt', 'wb') as f: