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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

from builtins import object 

import os 

import sqlite3 

from lsst.utils import getPackageDir 

 

__all__ = ['ScheduledDowntime'] 

 

 

class ScheduledDowntime(object): 

"""Handle the scheduled downtime information. 

 

This class handles the scheduled downtime information. 

""" 

 

SCHEDULED_DOWNTIME_DB = os.path.join(getPackageDir('sims_downtimeModel'), "data", "scheduled_downtime.db") 

 

def __init__(self): 

"""Initialize the class. 

""" 

self.downtime_file = None 

self.downtimes = [] 

 

def __call__(self): 

"""Return the top downtime. 

""" 

try: 

return self.downtimes.pop(0) 

except IndexError: 

return None 

 

def __len__(self): 

"""Return number of scheduled downtimes. 

 

Returns 

------- 

int 

""" 

return len(self.downtimes) 

 

def initialize(self, downtime_file=""): 

"""Configure the set of scheduled downtimes. 

 

This function gets the appropriate database file and creates the set of 

scheduled downtimes from it. The default behavior is to use the module stored 

database. However, an alternate database file can be provided. The alternate 

database file needs to have a table called *Downtime* with the following columns: 

 

night 

int : The night (from start of simulation) the downtime occurs. 

duration 

int : The duration (units=days) of the downtime. 

activity 

str : A description of the activity involved. 

 

Parameters 

---------- 

downtime_file : str, optional 

A full path to an alternate scheduled downtime database file. 

""" 

 

if downtime_file != "": 

self.downtime_file = downtime_file 

else: 

self.downtime_file = self.SCHEDULED_DOWNTIME_DB 

 

with sqlite3.connect(self.downtime_file) as conn: 

cur = conn.cursor() 

cur.execute("select * from Downtime;") 

for row in cur: 

self.downtimes.append((row[0], row[1], row[2])) 

cur.close() 

 

def get_downtimes(self, index): 

 

return self.downtimes[index]