Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2@file 

3@brief Data about timeseries. 

4""" 

5from datetime import datetime, timedelta 

6import numpy 

7 

8 

9def generate_sells(duration=730, end=None, 

10 week_coef=None, month_coef=None, 

11 trend=1.1): 

12 """ 

13 Generates dummy data and trends and seasonality. 

14 """ 

15 if week_coef is None: 

16 week_coef = numpy.array([0.1, 0.12, 0.12, 0.15, 0.20, 0., 0.]) 

17 week_coef[5] = 1. - week_coef.sum() 

18 if month_coef is None: 

19 month_coef = [0.8, 1, 1, 1, 1, 1, 

20 0.8, 0.6, 1, 1, 1, 1.5] 

21 month_coef = numpy.array(month_coef) 

22 month_coef /= month_coef.sum() 

23 

24 if end is None: 

25 end = datetime.now() 

26 begin = end - timedelta(duration) 

27 day = timedelta(1) 

28 

29 rows = [] 

30 rnd = (numpy.random.randn(duration + 1) * 0.1) + 1 

31 exp = (1 + numpy.exp(- numpy.arange(duration + 1) / duration * trend)) ** (-1) 

32 pos = 0 

33 while begin <= end: 

34 month = begin.month 

35 weekd = begin.weekday() 

36 value = rnd[pos] * week_coef[weekd] * month_coef[month - 1] * exp[pos] 

37 pos += 1 

38 obs = dict(date=begin, value=value) 

39 rows.append(obs) 

40 begin += day 

41 return rows