Skip to content

Instantly share code, notes, and snippets.

@smly smly/markov.py
Created Nov 29, 2013

Embed
What would you like to do?
import sys
import random
import json
import time
from influxdb import InfluxDBClient
def generate_gauss_value(mu, sigma, price=100.0, size=6*60*24*30):
current_timestamp = int(time.time())
yield current_timestamp, 100.0
for i in range(size):
price += random.gauss(mu, sigma)
current_timestamp -= 10
yield current_timestamp, price
def get_markov_chain_points(price=100.0):
return [[epoch, value] for epoch, value in
generate_gauss_value(0, 1, price)]
def main():
db = InfluxDBClient(
host='influxdb01',
port=8086,
username='smly',
password='secret',
database='testdb')
points = get_markov_chain_points(price=100.0)
while len(points) > 0:
request_param = [{
'name': 'markov',
'columns': ['time', 'value'],
'points': points[:1000]}]
db.write_points_with_precision(request_param)
points = points[1000:]
sys.stdout.write('.')
sys.stdout.flush()
print('done')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.