Created
November 29, 2013 19:56
-
-
Save smly/7711109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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