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#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*The stats table for ESO Phase III SSDR* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

11import khufu 

12from marshall_webapp.models.stats import models_stats_get 

13 

14def ssdr_stats_table( 

15 log, 

16 request, 

17 releaseVersion): 

18 """ssdr stats table 

19 

20 **Key Arguments** 

21 

22 - ``log`` -- logger 

23 - ``request`` -- the pyramid request 

24 - ``releaseVersion`` -- which release 

25  

26 

27 **Return** 

28 

29 - ``table`` -- the ssdr FITS file stats table 

30  

31 """ 

32 log.debug('starting the ``ssdr_stats_table`` function') 

33 

34 # get the table data 

35 thisTable = releaseVersion.lower() 

36 

37 stats = models_stats_get( 

38 log=log, 

39 request=request, 

40 elementId=releaseVersion 

41 ) 

42 result = stats.get() 

43 

44 fileTypes = result["fileTypes"] 

45 fileTotals = result["fileTotals"] 

46 

47 headerList = ["File Type", "Number of Files", "Data Volume"] 

48 

49 tableHead = "" 

50 for h in headerList: 

51 th = khufu.th( 

52 content=h, 

53 color=False 

54 ) 

55 tableHead = "%(tableHead)s%(th)s" % locals() 

56 tableHead = khufu.thead( 

57 trContent=tableHead 

58 ) 

59 

60 tableBody = "" 

61 for row in fileTypes: 

62 tableRow = "" 

63 fileType = row["filetype"].replace("_", " ").replace( 

64 "efosc", "EFOSC").replace("sofi", "SOFI") 

65 numberOfFiles = row["numberOfFiles"] 

66 # convert to GB 

67 dataVolume = float(row["dataVolumeBytes"]) / (1024. ** 3) 

68 if dataVolume < 1.: 

69 dataVolume = float(row["dataVolumeBytes"]) / (1024. ** 2) 

70 dataVolume = "%(dataVolume)0.2f MB" % locals() 

71 else: 

72 dataVolume = "%(dataVolume)0.2f GB" % locals() 

73 

74 td = khufu.td( 

75 content=fileType, 

76 color=False 

77 ) 

78 tableRow = "%(tableRow)s%(td)s" % locals() 

79 td = khufu.td( 

80 content=numberOfFiles, 

81 color=False 

82 ) 

83 tableRow = "%(tableRow)s%(td)s" % locals() 

84 td = khufu.td( 

85 content=dataVolume, 

86 color=False 

87 ) 

88 tableRow = "%(tableRow)s%(td)s" % locals() 

89 tr = khufu.tr( 

90 cellContent=tableRow, 

91 color=False 

92 ) 

93 tableRow = "" 

94 tableBody = "%(tableBody)s%(tr)s" % locals() 

95 

96 numberOfFiles = fileTotals[0]["numberOfFiles"] 

97 dataVolume = float(fileTotals[0]["dataVolumeBytes"]) / (1024. ** 3) 

98 if dataVolume < 1.: 

99 dataVolume = float(row["dataVolumeBytes"]) / (1024. ** 2) 

100 dataVolume = "%(dataVolume)0.2f MB" % locals() 

101 else: 

102 dataVolume = "%(dataVolume)0.2f GB" % locals() 

103 

104 tableRow = "" 

105 td = khufu.td( 

106 content="<strong>Total</strong>", 

107 color=False 

108 ) 

109 tableRow = "%(tableRow)s%(td)s" % locals() 

110 td = khufu.td( 

111 content=numberOfFiles, 

112 color=False 

113 ) 

114 tableRow = "%(tableRow)s%(td)s" % locals() 

115 td = khufu.td( 

116 content=dataVolume, 

117 color=False 

118 ) 

119 tableRow = "%(tableRow)s%(td)s" % locals() 

120 tr = khufu.tr( 

121 cellContent=tableRow, 

122 color=False 

123 ) 

124 tableBody = "%(tableBody)s%(tr)s" % locals() 

125 

126 tableBody = khufu.tbody( 

127 trContent=tableBody 

128 ) 

129 table = khufu.table( 

130 caption='', 

131 thead=tableHead, 

132 tbody=tableBody, 

133 striped=True 

134 ) 

135 

136 log.debug('completed the ``ssdr_stats_table`` function') 

137 return table