Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
stardate.py
Go to the documentation of this file.
1 import string
2 
3 # Independent of the date system used, this will scale how fast time progresses
4 # in VS.
5 # 0.1 will mean 10000 (real) seconds (~3h) = 1 (VS) year
6 # 1 will mean 1000 (real) seconds (~17min) = 1 (VS) year
7 # 2 will mean 500 (real) seconds (~ 8min) = 1 (VS) year ... ie time is twice as fast
8 SCALEFACTOR = 0.02 # ~14h gameplay = 1 VS year
9 
10 def formatStarDate(fac,stdt):
11  """Formats the stardate for news"""
12  stdtf=getFacCal(fac,stdt)
13  if fac == "confed":
14  return string.join([fillZeros(fac,stdtf[2]),str(stdtf[1]),str(stdtf[0]),formatTime(fac,stdt)])
15  else:
16  return string.join([fillZeros(fac,stdtf[2]),str(stdtf[1]),str(stdtf[0]),formatTime(fac,stdt)])
17 
18 def formatTime(fac,stdt):
19  """Formate the stardate time for news"""
20  stdtf=getFacCal(fac,stdt)
21  if fac == "confed":
22  return string.join([fillZeros(fac,stdtf[3]),fillZeros(fac,stdtf[4]),fillZeros(fac,stdtf[5])],":")
23  else:
24  return string.join([fillZeros(fac,stdtf[3]),fillZeros(fac,stdtf[4]),fillZeros(fac,stdtf[5])],":")
25 
26 def fillZeros(fac,tim):
27  """Returns a string with the required number of zeros for each faction"""
28  zer=2
29  tim=str(tim)
30  if fac == "confed":
31  zer=2
32  for i in range(zer):
33  if len(tim) < i+1:
34  tim='0'+tim
35  return tim
36 
37 def getFacCal(fac,stdt): #FIXME: add some other factions date systems....all ready to go :-)
38  """takes a stardate string and returns a list of ints with
39  [year,month,date,hour,minute,second]"""
40  datesys = getDateSystem(fac)
41  facstdt = (float(stdt)*SCALEFACTOR+float(getZeroStarDate(fac)))*datesys[3]
42  incyear = int(facstdt)/1000
43  return [incyear] + getMDDHMS(facstdt-(incyear*1000),datesys,incyear,fac)
44 
45 def daysinMonth(monthsystem,month):
46  for mon in monthsystem:
47  if mon[0] == month:
48  return mon[1]
49  return 1
50 
51 def daysinYear(monthsystem):
52  count = 0
53  for mon in monthsystem:
54  count+=mon[1]
55  return count
56 
57 def addMonthDays(monthsys,leap):
58  for i in range(len(monthsys)):
59  for lmon in leap:
60  if monthsys[i][0] == lmon[0]:
61  monthsys[i] = (monthsys[i][0],monthsys[i][1] + lmon[1])
62  return monthsys
63 
64 def getMDDHMS(frac,system,year,fac):
65  monthsystem = addMonthDays(system[0],getLeap(year,fac))
66  numdays = getStarToDay(monthsystem) * frac
67  remdays = numdays
68  countdays = 0
69  mon = monthsystem[0][0]
70  for i in range(len(monthsystem)):
71  countdays+=monthsystem[i][1]
72  if countdays >= numdays:
73  mon = monthsystem[i][0]
74  break
75  else:
76  remdays = numdays - countdays #FIXME: not sure exactly why the 1 is required, I think
77  #it is so that a fractional day would be counted as
78  #the 1st, 3.5 days into the month the 4th day etc
79  days = int(remdays)
80  remainder = remdays - days
81 
82  htemp = remainder * system[1][0]
83  hours = int(htemp)
84  mintemp = (htemp - hours) * system[1][1]
85  minutes = int(mintemp)
86  sectemp = (mintemp - minutes) * system[1][2]
87  seconds = int(sectemp)
88  return [mon,days+1,hours,minutes,seconds]
89 
90 
91 def getDateSystem(faction):
92  """returns a particlar races standard date system (not including leap years)"""
93  if facDateSystems().has_key(faction):
94  return facDateSystems()[faction]
95  else:
96  return facDateSystems()["standard"]
97 
98 
99 def getStarToDay(monthsystem):
100  """returns a particlar races stardate to day ratio"""
101  return daysinYear(monthsystem) / 1000.0
102 
103 def getZeroStarDate(faction):
104  """Returns the VS stardate at which each faction has the zero date."""
105  if faction == "confed":
106  return 3276800
107  else:
108  return 3276800
109 
110 def getLeap(year,faction):
111  if faction == "confed":
112  if year%100 == 0:
113  return list()
114  elif year%4 == 0:
115  return [("February",1)]
116  else:
117  return list()
118  else:
119  if year%100 == 0:
120  return list()
121  elif year%4 == 0:
122  return [("February",1)]
123  else:
124  return list()
125 
127  """returns the date systems for all the factions with special ones.
128  It is a tuple, with the first item a list of (month,#days) tuples, the second
129  a tuple with (#hoursperday,#minutesperhour,#secondsperminute), the third is
130  a list of the names for the time divisions, and the last is the number of
131  cycles (years) per standard kilostardate."""
132  return {
133  "standard" :
134  ([("January",31),("February",28),("March",31),("April",30),("May",31),("June",30),("July",31),("August",31),("September",30),("October",31),("November",30),("December",31)],(24,60,60),["year","month","week","day","hour","minute","second"],1)
135  }
136