source: src/python/bin/gnuboat-data-generator@ 008bce9

0.5 debian/bullseye debian/jessie
Last change on this file since 008bce9 was e44e1f1, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago

Added a python script to generate demo data into an rrd file

  • Property mode set to 100755
File size: 4.4 KB
RevLine 
[e44e1f1]1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3'''
4 Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18'''
19
20import rrdtool
21import argparse
22import random
23import time
24import sys
25import os
26
27from gnuboat import daemon
28
29# default values for command line arguments
30rrdfile = "/var/lib/gnuboat/gnuboat.rrd"
31# in seconds
32logperiod = 2
33duration = 24 * 60 * 60
34latitude_min = -90
35latitude_max = 90
36longitude_min = -180
37longitude_max = 180
38
39def main(argv):
40 global rrdfile
41 global duration
42 global latitude_min
43 global latitude_max
44 global longitude_min
45 global longitude_max
46 global logperiod
47
48 parser = argparse.ArgumentParser(description="Generates test data for gnuboat webservice and fills the rrd database")
49 parser.add_argument('-f', '--file', dest='rrd_database', metavar='rrd_database', type=str,
50 help='File path of the rrd database to fill', default="/var/lib/gnuboat/gnuboat.rrd")
51 parser.add_argument('-lat-min', '--latitude-min', dest='lat_min', metavar='lat_min', type=float,
52 help='Minimum latitude generated', default=latitude_min)
53 parser.add_argument('-lat-max', '--latitude-max', dest='lat_max', metavar='lat_max', type=float,
54 help='Maximum latitude generated', default=latitude_max)
55 parser.add_argument('-lon-min', '--longitude-min', dest='lon_min', metavar='lon_min', type=float,
56 help='Minimum longitude generated', default=longitude_min)
57 parser.add_argument('-lon-max', '--longitude-max', dest='lon_max', metavar='lon_max', type=float,
58 help='Maximum longitude generated', default=longitude_max)
59 parser.add_argument('-l', '--logperiod', dest='logperiod', metavar='logperiod', type=int,
60 help='Period of data generation (seconds between two values)', default=logperiod)
61 arguments = parser.parse_args(argv)
62
63 if arguments.rrd_database is not None:
64 rrdfile = arguments.rrd_database
65
66 if arguments.lat_min is not None:
67 latitude_min = arguments.lat_min
68 if arguments.lat_max is not None:
69 latitude_max = arguments.lat_max
70
71 if arguments.lon_min is not None:
72 longitude_min = arguments.lon_min
73 if arguments.lon_max is not None:
74 longitude_max = arguments.lon_max
75
76 if arguments.logperiod is not None:
77 logperiod = arguments.logperiod
78
79 if not os.path.exists(os.path.dirname(rrdfile)):
80 print "rrd database directory not found %s" % os.path.dirname(rrdfile)
81 print ""
82 parser.print_help()
83 sys.exit(2)
84
85 timestamp = int(time.time())
86 start_time = timestamp - duration - logperiod
87
88 if os.path.isfile(rrdfile):
89 print "Removing old database %s" % rrdfile
90 os.remove(rrdfile)
91
92 print "Creating %s" % rrdfile
93 daemon.rrd_create_database(rrdfile, logperiod, str(start_time))
94
95 print "Filling database inside [%s, %s] --> [%s,%s]..." % (latitude_min, longitude_min, latitude_max, longitude_max)
96 for current_time in xrange(timestamp - duration, timestamp, logperiod):
97 latitude = random.uniform(latitude_min, latitude_max)
98 longitude = random.uniform(longitude_min, longitude_max)
99 speedThroughWater = random.randint(0, 10)
100 speedOverGround = random.randint(-2, 15)
101 courseOverGround = random.randint(0, 360)
102 waterDepth = random.randint(0, 20)
103 waterTemperature = random.randint(2, 25)
104 gpsFix = 3
105 # update rrd database for the webservice
106 daemon.rrd_update(rrdfile, "%s:%s:%s:%s:%s:%s:%s:%s:%s" % (
107 current_time, latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix))
108
109if __name__ == "__main__":
110 main(sys.argv[1:])
Note: See TracBrowser for help on using the repository browser.