parser.add_argument('--min-bets', '-b', default=4, type=int) parser.add_argument('--top-k', '-k', action='store_true', help='Top k good bets instead of all good bets ' 'normalized') args = parser.parse_args() money = args.money min_bets = args.min_bets start_date = args.week_start if isinstance(start_date, str): start_date = dateutil.parser.parse(start_date) # Find the closest thursday next_thurs = start_date + relativedelta(weekday=TH(+1)) prev_thurs = start_date + relativedelta(weekday=TH(-1)) start_date = (next_thurs if (next_thurs - start_date).days < (start_date - prev_thurs).days else prev_thurs) end_date = start_date + timedelta(days=6) print('Gambling for week starting on %s and ending %s.' % (str(start_date.date()), str(end_date.date()))) # read in lines lines_df = pd.read_csv(args.lines) teams = list(lines_df.loc[:, 'Away Team']) teams.extend(list(lines_df.loc[:, 'Home Team'])) lines = list(lines_df.loc[:, 'Money Line']) lines.extend(list(lines_df.loc[:, 'Money Line.1'])) lines = dict(zip(teams, lines))
def _populate(self, year): # New Year's Day if year > 1870: name = "New Year's Day" self[date(year, JAN, 1)] = name if self.observed and date(year, JAN, 1).weekday() == SUN: self[date(year, JAN, 1) + rd(days=+1)] = name + \ " (Observed)" elif self.observed \ and date(year, JAN, 1).weekday() == SAT: # Add Dec 31st from the previous year without triggering # the entire year to be added expand = self.expand self.expand = False self[date(year, JAN, 1) + rd(days=-1)] = name + \ " (Observed)" self.expand = expand # The next year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday) if self.observed and date(year, DEC, 31).weekday() == FRI: self[date(year, DEC, 31)] = name + " (Observed)" # Epiphany if self.state == 'PR': self[date(year, JAN, 6)] = "Epiphany" # Three King's Day if self.state == 'VI': self[date(year, JAN, 6)] = "Three King's Day" # Lee Jackson Day name = "Lee Jackson Day" if self.state == 'VA' and year >= 2000: dt = date(year, JAN, 1) + rd(weekday=MO(+3)) + rd( weekday=FR(-1)) self[dt] = name elif self.state == 'VA' and year >= 1983: self[date(year, JAN, 1) + rd(weekday=MO(+3))] = name elif self.state == 'VA' and year >= 1889: self[date(year, JAN, 19)] = name # Inauguration Day if self.state in ('DC', 'LA', 'MD', 'VA') and year >= 1789: name = "Inauguration Day" if (year - 1789) % 4 == 0 and year >= 1937: self[date(year, JAN, 20)] = name if date(year, JAN, 20).weekday() == SUN: self[date(year, JAN, 21)] = name + " (Observed)" elif (year - 1789) % 4 == 0: self[date(year, MAR, 4)] = name if date(year, MAR, 4).weekday() == SUN: self[date(year, MAR, 5)] = name + " (Observed)" # Martin Luther King Jr. Day if year >= 1986: name = "Martin Luther King Jr. Day" if self.state == 'AL': name = "Robert E. Lee/Martin Luther King Birthday" elif (self.state == 'MS') or ((self.state == 'AR') and (year <= 2017)): name = ("Dr. Martin Luther King Jr. " "and Robert E. Lee's Birthdays") elif self.state in ('AZ', 'NH'): name = "Dr. Martin Luther King Jr./Civil Rights Day" elif self.state == 'GA' and year < 2012: name = "Robert E. Lee's Birthday" elif self.state == 'ID' and year >= 2006: name = "Martin Luther King, Jr. - Idaho Human Rights Day" self[date(year, JAN, 1) + rd(weekday=MO(+3))] = name # Lincoln's Birthday name = "Lincoln's Birthday" if (self.state in ('CT', 'IL', 'IA', 'NJ', 'NY') and year >= 1971) \ or (self.state == 'CA' and 1971 <= year <= 2009): self[date(year, FEB, 12)] = name if self.observed \ and date(year, FEB, 12).weekday() == SAT: self[date(year, FEB, 11)] = name + " (Observed)" elif self.observed \ and date(year, FEB, 12).weekday() == SUN: self[date(year, FEB, 13)] = name + " (Observed)" # Susan B. Anthony Day if (self.state == 'CA' and year >= 2014) \ or (self.state == 'FL' and year >= 2011) \ or (self.state == 'NY' and year >= 2004) \ or (self.state == 'WI' and year >= 1976): self[date(year, FEB, 15)] = "Susan B. Anthony Day" # Washington's Birthday name = "Washington's Birthday" if self.state == 'AL': name = "George Washington/Thomas Jefferson Birthday" elif self.state == 'AR': name = "George Washington's Birthday and Daisy Gatson Bates Day" elif self.state in ('PR', 'VI'): name = "Presidents' Day" if self.state not in ('DE', 'FL', 'GA', 'NM', 'PR'): if year > 1970: self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name elif year >= 1879: self[date(year, FEB, 22)] = name elif self.state == 'GA': if date(year, DEC, 24).weekday() != WED: self[date(year, DEC, 24)] = name else: self[date(year, DEC, 26)] = name elif self.state in ('PR', 'VI'): self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name # Mardi Gras if self.state == 'LA' and year >= 1857: self[easter(year) + rd(days=-47)] = "Mardi Gras" # Guam Discovery Day if self.state == 'GU' and year >= 1970: self[date(year, MAR, 1) + rd(weekday=MO)] = "Guam Discovery Day" # Casimir Pulaski Day if self.state == 'IL' and year >= 1978: self[date(year, MAR, 1) + rd(weekday=MO)] = "Casimir Pulaski Day" # Texas Independence Day if self.state == 'TX' and year >= 1874: self[date(year, MAR, 2)] = "Texas Independence Day" # Town Meeting Day if self.state == 'VT' and year >= 1800: self[date(year, MAR, 1) + rd(weekday=TU)] = "Town Meeting Day" # Evacuation Day if self.state == 'MA' and year >= 1901: name = "Evacuation Day" self[date(year, MAR, 17)] = name if date(year, MAR, 17).weekday() in WEEKEND: self[date(year, MAR, 17) + rd(weekday=MO)] = name + \ " (Observed)" # Emancipation Day if self.state == 'PR': self[date(year, MAR, 22)] = "Emancipation Day" if self.observed and date(year, MAR, 22).weekday() == SUN: self[date(year, MAR, 23)] = "Emancipation Day (Observed)" # Prince Jonah Kuhio Kalanianaole Day if self.state == 'HI' and year >= 1949: name = "Prince Jonah Kuhio Kalanianaole Day" self[date(year, MAR, 26)] = name if self.observed and date(year, MAR, 26).weekday() == SAT: self[date(year, MAR, 25)] = name + " (Observed)" elif self.observed and date(year, MAR, 26).weekday() == SUN: self[date(year, MAR, 27)] = name + " (Observed)" # Steward's Day name = "Steward's Day" if self.state == 'AK' and year >= 1955: self[date(year, APR, 1) + rd(days=-1, weekday=MO(-1))] = name elif self.state == 'AK' and year >= 1918: self[date(year, MAR, 30)] = name # César Chávez Day name = "César Chávez Day" if self.state == 'CA' and year >= 1995: self[date(year, MAR, 31)] = name if self.observed and date(year, MAR, 31).weekday() == SUN: self[date(year, APR, 1)] = name + " (Observed)" elif self.state == 'TX' and year >= 2000: self[date(year, MAR, 31)] = name # Transfer Day if self.state == 'VI': self[date(year, MAR, 31)] = "Transfer Day" # Emancipation Day if self.state == 'DC' and year >= 2005: name = "Emancipation Day" self[date(year, APR, 16)] = name if self.observed and date(year, APR, 16).weekday() == SAT: self[date(year, APR, 15)] = name + " (Observed)" elif self.observed and date(year, APR, 16).weekday() == SUN: self[date(year, APR, 17)] = name + " (Observed)" # Patriots' Day if self.state in ('ME', 'MA') and year >= 1969: self[date(year, APR, 1) + rd(weekday=MO(+3))] = "Patriots' Day" elif self.state in ('ME', 'MA') and year >= 1894: self[date(year, APR, 19)] = "Patriots' Day" # Holy Thursday if self.state == 'VI': self[easter(year) + rd(weekday=TH(-1))] = "Holy Thursday" # Good Friday if self.state in ('CT', 'DE', 'GU', 'IN', 'KY', 'LA', 'NJ', 'NC', 'PR', 'TN', 'TX', 'VI'): self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" # Easter Monday if self.state == 'VI': self[easter(year) + rd(weekday=MO)] = "Easter Monday" # Confederate Memorial Day name = "Confederate Memorial Day" if self.state in ('AL', 'GA', 'MS', 'SC') and year >= 1866: if self.state == 'GA' and year >= 2016: name = "State Holiday" if self.state == 'GA' and year == 2020: self[date(year, APR, 10)] = name else: self[date(year, APR, 1) + rd(weekday=MO(+4))] = name elif self.state == 'TX' and year >= 1931: self[date(year, JAN, 19)] = name # San Jacinto Day if self.state == 'TX' and year >= 1875: self[date(year, APR, 21)] = "San Jacinto Day" # Arbor Day if self.state == 'NE' and year >= 1989: self[date(year, APR, 30) + rd(weekday=FR(-1))] = "Arbor Day" elif self.state == 'NE' and year >= 1875: self[date(year, APR, 22)] = "Arbor Day" # Primary Election Day if self.state == 'IN' and \ ((year >= 2006 and year % 2 == 0) or year >= 2015): dt = date(year, MAY, 1) + rd(weekday=MO) self[dt + rd(days=+1)] = "Primary Election Day" # Truman Day if self.state == 'MO' and year >= 1949: name = "Truman Day" self[date(year, MAY, 8)] = name if self.observed and date(year, MAY, 8).weekday() == SAT: self[date(year, MAY, 7)] = name + " (Observed)" elif self.observed and date(year, MAY, 8).weekday() == SUN: self[date(year, MAY, 10)] = name + " (Observed)" # Memorial Day if year > 1970: self[date(year, MAY, 31) + rd(weekday=MO(-1))] = "Memorial Day" elif year >= 1888: self[date(year, MAY, 30)] = "Memorial Day" # Jefferson Davis Birthday name = "Jefferson Davis Birthday" if self.state == 'AL' and year >= 1890: self[date(year, JUN, 1) + rd(weekday=MO)] = name # Kamehameha Day if self.state == 'HI' and year >= 1872: self[date(year, JUN, 11)] = "Kamehameha Day" if self.observed and year >= 2011: if date(year, JUN, 11).weekday() == SAT: self[date(year, JUN, 10)] = "Kamehameha Day (Observed)" elif date(year, JUN, 11).weekday() == SUN: self[date(year, JUN, 12)] = "Kamehameha Day (Observed)" # Emancipation Day In Texas if self.state == 'TX' and year >= 1980: self[date(year, JUN, 19)] = "Emancipation Day In Texas" # West Virginia Day name = "West Virginia Day" if self.state == 'WV' and year >= 1927: self[date(year, JUN, 20)] = name if self.observed and date(year, JUN, 20).weekday() == SAT: self[date(year, JUN, 19)] = name + " (Observed)" elif self.observed and date(year, JUN, 20).weekday() == SUN: self[date(year, JUN, 21)] = name + " (Observed)" # Emancipation Day in US Virgin Islands if self.state == 'VI': self[date(year, JUL, 3)] = "Emancipation Day" # Independence Day if year > 1870: name = "Independence Day" self[date(year, JUL, 4)] = name if self.observed and date(year, JUL, 4).weekday() == SAT: self[date(year, JUL, 4) + rd(days=-1)] = name + " (Observed)" elif self.observed and date(year, JUL, 4).weekday() == SUN: self[date(year, JUL, 4) + rd(days=+1)] = name + " (Observed)" # Liberation Day (Guam) if self.state == 'GU' and year >= 1945: self[date(year, JUL, 21)] = "Liberation Day (Guam)" # Pioneer Day if self.state == 'UT' and year >= 1849: name = "Pioneer Day" self[date(year, JUL, 24)] = name if self.observed and date(year, JUL, 24).weekday() == SAT: self[date(year, JUL, 24) + rd(days=-1)] = name + " (Observed)" elif self.observed and date(year, JUL, 24).weekday() == SUN: self[date(year, JUL, 24) + rd(days=+1)] = name + " (Observed)" # Constitution Day if self.state == 'PR': self[date(year, JUL, 25)] = "Constitution Day" if self.observed and date(year, JUL, 25).weekday() == SUN: self[date(year, JUL, 26)] = "Constitution Day (Observed)" # Victory Day if self.state == 'RI' and year >= 1948: self[date(year, AUG, 1) + rd(weekday=MO(+2))] = "Victory Day" # Statehood Day (Hawaii) if self.state == 'HI' and year >= 1959: self[date(year, AUG, 1) + rd(weekday=FR(+3))] = "Statehood Day" # Bennington Battle Day if self.state == 'VT' and year >= 1778: name = "Bennington Battle Day" self[date(year, AUG, 16)] = name if self.observed and date(year, AUG, 16).weekday() == SAT: self[date(year, AUG, 15)] = name + " (Observed)" elif self.observed and date(year, AUG, 16).weekday() == SUN: self[date(year, AUG, 17)] = name + " (Observed)" # Lyndon Baines Johnson Day if self.state == 'TX' and year >= 1973: self[date(year, AUG, 27)] = "Lyndon Baines Johnson Day" # Labor Day if year >= 1894: self[date(year, SEP, 1) + rd(weekday=MO)] = "Labor Day" # Columbus Day if self.state not in ('AK', 'AR', 'DE', 'FL', 'HI', 'NV'): if self.state == 'SD': name = "Native American Day" elif self.state == 'VI': name = "Columbus Day and Puerto Rico Friendship Day" else: name = "Columbus Day" if year >= 1970: self[date(year, OCT, 1) + rd(weekday=MO(+2))] = name elif year >= 1937: self[date(year, OCT, 12)] = name # Alaska Day if self.state == 'AK' and year >= 1867: name = "Alaska Day" self[date(year, OCT, 18)] = name if self.observed \ and date(year, OCT, 18).weekday() == SAT: self[date(year, OCT, 18) + rd(days=-1)] = name + \ " (Observed)" elif self.observed \ and date(year, OCT, 18).weekday() == SUN: self[date(year, OCT, 18) + rd(days=+1)] = name + \ " (Observed)" # Nevada Day if self.state == 'NV' and year >= 1933: dt = date(year, OCT, 31) if year >= 2000: dt += rd(weekday=FR(-1)) self[dt] = "Nevada Day" if self.observed and dt.weekday() == SAT: self[dt + rd(days=-1)] = "Nevada Day (Observed)" elif self.observed and dt.weekday() == SUN: self[dt + rd(days=+1)] = "Nevada Day (Observed)" # Liberty Day if self.state == 'VI': self[date(year, NOV, 1)] = "Liberty Day" # Election Day if (self.state in ('DE', 'HI', 'IL', 'IN', 'LA', 'MT', 'NH', 'NJ', 'NY', 'WV') and year >= 2008 and year % 2 == 0) \ or (self.state in ('IN', 'NY') and year >= 2015): dt = date(year, NOV, 1) + rd(weekday=MO) self[dt + rd(days=+1)] = "Election Day" # All Souls' Day if self.state == 'GU': self[date(year, NOV, 2)] = "All Souls' Day" # Veterans Day if year > 1953: name = "Veterans Day" else: name = "Armistice Day" if 1978 > year > 1970: self[date(year, OCT, 1) + rd(weekday=MO(+4))] = name elif year >= 1938: self[date(year, NOV, 11)] = name if self.observed \ and date(year, NOV, 11).weekday() == SAT: self[date(year, NOV, 11) + rd(days=-1)] = name + \ " (Observed)" elif self.observed \ and date(year, NOV, 11).weekday() == SUN: self[date(year, NOV, 11) + rd(days=+1)] = name + \ " (Observed)" # Discovery Day if self.state == 'PR': self[date(year, NOV, 19)] = "Discovery Day" if self.observed and date(year, NOV, 19).weekday() == SUN: self[date(year, NOV, 20)] = "Discovery Day (Observed)" # Thanksgiving if year > 1870: self[date(year, NOV, 1) + rd(weekday=TH(+4))] = "Thanksgiving" # Day After Thanksgiving # Friday After Thanksgiving # Lincoln's Birthday # American Indian Heritage Day # Family Day # New Mexico Presidents' Day if (self.state in ('DE', 'FL', 'NH', 'NC', 'OK', 'TX', 'WV') and year >= 1975) \ or (self.state == 'IN' and year >= 2010) \ or (self.state == 'MD' and year >= 2008) \ or self.state in ('NV', 'NM'): if self.state in ('DE', 'NH', 'NC', 'OK', 'WV'): name = "Day After Thanksgiving" elif self.state in ('FL', 'TX'): name = "Friday After Thanksgiving" elif self.state == 'IN': name = "Lincoln's Birthday" elif self.state == 'MD' and year >= 2008: name = "American Indian Heritage Day" elif self.state == 'NV': name = "Family Day" elif self.state == 'NM': name = "Presidents' Day" dt = date(year, NOV, 1) + rd(weekday=TH(+4)) self[dt + rd(days=+1)] = name # Robert E. Lee's Birthday if self.state == 'GA' and year >= 1986: if year >= 2016: name = "State Holiday" else: name = "Robert E. Lee's Birthday" self[date(year, NOV, 29) + rd(weekday=FR(-1))] = name # Lady of Camarin Day if self.state == 'GU': self[date(year, DEC, 8)] = "Lady of Camarin Day" # Christmas Eve if self.state == 'AS' or \ (self.state in ('KS', 'MI', 'NC') and year >= 2013) or \ (self.state == 'TX' and year >= 1981) or \ (self.state == 'WI' and year >= 2012): name = "Christmas Eve" self[date(year, DEC, 24)] = name name = name + " (Observed)" # If on Friday, observed on Thursday if self.observed and date(year, DEC, 24).weekday() == FRI: self[date(year, DEC, 24) + rd(days=-1)] = name # If on Saturday or Sunday, observed on Friday elif self.observed \ and date(year, DEC, 24).weekday() in WEEKEND: self[date(year, DEC, 24) + rd(weekday=FR(-1))] = name # Christmas Day if year > 1870: name = "Christmas Day" self[date(year, DEC, 25)] = "Christmas Day" if self.observed \ and date(year, DEC, 25).weekday() == SAT: self[date(year, DEC, 25) + rd(days=-1)] = name + \ " (Observed)" elif self.observed \ and date(year, DEC, 25).weekday() == SUN: self[date(year, DEC, 25) + rd(days=+1)] = name + \ " (Observed)" # Day After Christmas if self.state == 'NC' and year >= 2013: name = "Day After Christmas" self[date(year, DEC, 26)] = name name = name + " (Observed)" # If on Saturday or Sunday, observed on Monday if self.observed and date(year, DEC, 26).weekday() in WEEKEND: self[date(year, DEC, 26) + rd(weekday=MO)] = name # If on Monday, observed on Tuesday elif self.observed \ and date(year, DEC, 26).weekday() == MON: self[date(year, DEC, 26) + rd(days=+1)] = name elif self.state == 'TX' and year >= 1981: self[date(year, DEC, 26)] = "Day After Christmas" elif self.state == 'VI': self[date(year, DEC, 26)] = "Christmas Second Day" # New Year's Eve if (self.state in ('KY', 'MI') and year >= 2013) or \ (self.state == 'WI' and year >= 2012): name = "New Year's Eve" self[date(year, DEC, 31)] = name if self.observed \ and date(year, DEC, 31).weekday() == SAT: self[date(year, DEC, 30)] = name + " (Observed)"
def demo_weekday(): childrenday = date(2016, 1, 1) + relativedelta(weekday=SA(+2)) print(childrenday) print(datetime.strftime(childrenday, "%a %b %d %m %y")) thanksgiving = date(2016, 11, 1) + relativedelta(weekday=TH(4)) print(datetime.strftime(thanksgiving, "%a %b %d-%m-%Y"))
def _populate(self, year): # New Year's Day if year > 1870: name = "New Year's Day" self[date(year, JAN, 1)] = name if self.observed and date(year, JAN, 1).weekday() == SUN: self[date(year, JAN, 1) + rd(days=+1)] = name + " (Observed)" elif self.observed and date(year, JAN, 1).weekday() == SAT: # Add Dec 31st from the previous year without triggering # the entire year to be added expand = self.expand self.expand = False self[date(year, JAN, 1) + rd(days=-1)] = name + " (Observed)" self.expand = expand # The next year's observed New Year's Day can be in this year # when it falls on a Friday (Jan 1st is a Saturday) if self.observed and date(year, DEC, 31).weekday() == FRI: self[date(year, DEC, 31)] = name + " (Observed)" # Epiphany if self.state == "PR": self[date(year, JAN, 6)] = "Epiphany" # Three King's Day if self.state == "VI": self[date(year, JAN, 6)] = "Three King's Day" # Lee Jackson Day name = "Lee Jackson Day" if self.state == "VA" and year >= 2000: dt = date(year, JAN, 1) + rd(weekday=MO(+3)) + rd(weekday=FR(-1)) self[dt] = name elif self.state == "VA" and year >= 1983: self[date(year, JAN, 1) + rd(weekday=MO(+3))] = name elif self.state == "VA" and year >= 1889: self[date(year, JAN, 19)] = name # Inauguration Day if self.state in ("DC", "LA", "MD", "VA") and year >= 1789: name = "Inauguration Day" if (year - 1789) % 4 == 0 and year >= 1937: self[date(year, JAN, 20)] = name if date(year, JAN, 20).weekday() == SUN: self[date(year, JAN, 21)] = name + " (Observed)" elif (year - 1789) % 4 == 0: self[date(year, MAR, 4)] = name if date(year, MAR, 4).weekday() == SUN: self[date(year, MAR, 5)] = name + " (Observed)" # Martin Luther King Jr. Day if year >= 1986: name = "Martin Luther King Jr. Day" if self.state == "AL": name = "Robert E. Lee/Martin Luther King Birthday" elif (self.state == "MS") or ((self.state == "AR") and (year <= 2017)): name = ("Dr. Martin Luther King Jr. " "and Robert E. Lee's Birthdays") elif self.state in ("AZ", "NH"): name = "Dr. Martin Luther King Jr./Civil Rights Day" elif self.state == "GA" and year < 2012: name = "Robert E. Lee's Birthday" elif self.state == "ID" and year >= 2006: name = "Martin Luther King Jr. - Idaho Human Rights Day" self[date(year, JAN, 1) + rd(weekday=MO(+3))] = name # Lincoln's Birthday name = "Lincoln's Birthday" if (self.state in ("CT", "IL", "IA", "NJ", "NY") and year >= 1971) or (self.state == "CA" and 1971 <= year <= 2009): self[date(year, FEB, 12)] = name if self.observed and date(year, FEB, 12).weekday() == SAT: self[date(year, FEB, 11)] = name + " (Observed)" elif self.observed and date(year, FEB, 12).weekday() == SUN: self[date(year, FEB, 13)] = name + " (Observed)" # Susan B. Anthony Day if ((self.state == "CA" and year >= 2014) or (self.state == "FL" and year >= 2011) or (self.state == "NY" and year >= 2004) or (self.state == "WI" and year >= 1976)): self[date(year, FEB, 15)] = "Susan B. Anthony Day" # Washington's Birthday name = "Washington's Birthday" if self.state == "AL": name = "George Washington/Thomas Jefferson Birthday" elif self.state == "AR": name = "George Washington's Birthday and Daisy Gatson Bates Day" elif self.state in ("PR", "VI"): name = "Presidents' Day" if self.state not in ("DE", "FL", "GA", "NM", "PR"): if year > 1970: self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name elif year >= 1879: self[date(year, FEB, 22)] = name elif self.state == "GA": if date(year, DEC, 24).weekday() != WED: self[date(year, DEC, 24)] = name else: self[date(year, DEC, 26)] = name elif self.state in ("PR", "VI"): self[date(year, FEB, 1) + rd(weekday=MO(+3))] = name # Mardi Gras if self.state == "LA" and year >= 1857: self[easter(year) + rd(days=-47)] = "Mardi Gras" # Guam Discovery Day if self.state == "GU" and year >= 1970: self[date(year, MAR, 1) + rd(weekday=MO)] = "Guam Discovery Day" # Casimir Pulaski Day if self.state == "IL" and year >= 1978: self[date(year, MAR, 1) + rd(weekday=MO)] = "Casimir Pulaski Day" # Texas Independence Day if self.state == "TX" and year >= 1874: self[date(year, MAR, 2)] = "Texas Independence Day" # Town Meeting Day if self.state == "VT" and year >= 1800: self[date(year, MAR, 1) + rd(weekday=TU)] = "Town Meeting Day" # Evacuation Day if self.state == "MA" and year >= 1901: name = "Evacuation Day" self[date(year, MAR, 17)] = name if date(year, MAR, 17).weekday() in WEEKEND: self[date(year, MAR, 17) + rd(weekday=MO)] = (name + " (Observed)") # Emancipation Day if self.state == "PR": self[date(year, MAR, 22)] = "Emancipation Day" if self.observed and date(year, MAR, 22).weekday() == SUN: self[date(year, MAR, 23)] = "Emancipation Day (Observed)" # Prince Jonah Kuhio Kalanianaole Day if self.state == "HI" and year >= 1949: name = "Prince Jonah Kuhio Kalanianaole Day" self[date(year, MAR, 26)] = name if self.observed and date(year, MAR, 26).weekday() == SAT: self[date(year, MAR, 25)] = name + " (Observed)" elif self.observed and date(year, MAR, 26).weekday() == SUN: self[date(year, MAR, 27)] = name + " (Observed)" # Steward's Day name = "Steward's Day" if self.state == "AK" and year >= 1955: self[date(year, APR, 1) + rd(days=-1, weekday=MO(-1))] = name elif self.state == "AK" and year >= 1918: self[date(year, MAR, 30)] = name # César Chávez Day name = "César Chávez Day" if self.state == "CA" and year >= 1995: self[date(year, MAR, 31)] = name if self.observed and date(year, MAR, 31).weekday() == SUN: self[date(year, APR, 1)] = name + " (Observed)" elif self.state == "TX" and year >= 2000: self[date(year, MAR, 31)] = name # Transfer Day if self.state == "VI": self[date(year, MAR, 31)] = "Transfer Day" # Emancipation Day if self.state == "DC" and year >= 2005: name = "Emancipation Day" self[date(year, APR, 16)] = name if self.observed and date(year, APR, 16).weekday() == SAT: self[date(year, APR, 15)] = name + " (Observed)" elif self.observed and date(year, APR, 16).weekday() == SUN: self[date(year, APR, 17)] = name + " (Observed)" # Patriots' Day if self.state in ("ME", "MA") and year >= 1969: self[date(year, APR, 1) + rd(weekday=MO(+3))] = "Patriots' Day" elif self.state in ("ME", "MA") and year >= 1894: self[date(year, APR, 19)] = "Patriots' Day" # Holy Thursday if self.state == "VI": self[easter(year) + rd(weekday=TH(-1))] = "Holy Thursday" # Good Friday if self.state in ( "CT", "DE", "GU", "IN", "KY", "LA", "NJ", "NC", "PR", "TN", "TX", "VI", ): self[easter(year) + rd(weekday=FR(-1))] = "Good Friday" # Easter Monday if self.state == "VI": self[easter(year) + rd(weekday=MO)] = "Easter Monday" # Confederate Memorial Day name = "Confederate Memorial Day" if self.state in ("AL", "GA", "MS", "SC") and year >= 1866: if self.state == "GA" and year >= 2016: name = "State Holiday" if self.state == "GA" and year == 2020: self[date(year, APR, 10)] = name else: self[date(year, APR, 1) + rd(weekday=MO(+4))] = name elif self.state == "TX" and year >= 1931: self[date(year, JAN, 19)] = name # San Jacinto Day if self.state == "TX" and year >= 1875: self[date(year, APR, 21)] = "San Jacinto Day" # Arbor Day if self.state == "NE" and year >= 1989: self[date(year, APR, 30) + rd(weekday=FR(-1))] = "Arbor Day" elif self.state == "NE" and year >= 1875: self[date(year, APR, 22)] = "Arbor Day" # Primary Election Day if self.state == "IN" and ((year >= 2006 and year % 2 == 0) or year >= 2015): dt = date(year, MAY, 1) + rd(weekday=MO) self[dt + rd(days=+1)] = "Primary Election Day" # Truman Day if self.state == "MO" and year >= 1949: name = "Truman Day" self[date(year, MAY, 8)] = name if self.observed and date(year, MAY, 8).weekday() == SAT: self[date(year, MAY, 7)] = name + " (Observed)" elif self.observed and date(year, MAY, 8).weekday() == SUN: self[date(year, MAY, 10)] = name + " (Observed)" # Memorial Day if year > 1970: self[date(year, MAY, 31) + rd(weekday=MO(-1))] = "Memorial Day" elif year >= 1888: self[date(year, MAY, 30)] = "Memorial Day" # Jefferson Davis Birthday name = "Jefferson Davis Birthday" if self.state == "AL" and year >= 1890: self[date(year, JUN, 1) + rd(weekday=MO)] = name # Kamehameha Day if self.state == "HI" and year >= 1872: self[date(year, JUN, 11)] = "Kamehameha Day" if self.observed and year >= 2011: if date(year, JUN, 11).weekday() == SAT: self[date(year, JUN, 10)] = "Kamehameha Day (Observed)" elif date(year, JUN, 11).weekday() == SUN: self[date(year, JUN, 12)] = "Kamehameha Day (Observed)" # Emancipation Day In Texas if self.state == "TX" and year >= 1980: self[date(year, JUN, 19)] = "Emancipation Day In Texas" # West Virginia Day name = "West Virginia Day" if self.state == "WV" and year >= 1927: self[date(year, JUN, 20)] = name if self.observed and date(year, JUN, 20).weekday() == SAT: self[date(year, JUN, 19)] = name + " (Observed)" elif self.observed and date(year, JUN, 20).weekday() == SUN: self[date(year, JUN, 21)] = name + " (Observed)" # Emancipation Day in US Virgin Islands if self.state == "VI": self[date(year, JUL, 3)] = "Emancipation Day" # Independence Day if year > 1870: name = "Independence Day" self[date(year, JUL, 4)] = name if self.observed and date(year, JUL, 4).weekday() == SAT: self[date(year, JUL, 4) + rd(days=-1)] = name + " (Observed)" elif self.observed and date(year, JUL, 4).weekday() == SUN: self[date(year, JUL, 4) + rd(days=+1)] = name + " (Observed)" # Liberation Day (Guam) if self.state == "GU" and year >= 1945: self[date(year, JUL, 21)] = "Liberation Day (Guam)" # Pioneer Day if self.state == "UT" and year >= 1849: name = "Pioneer Day" self[date(year, JUL, 24)] = name if self.observed and date(year, JUL, 24).weekday() == SAT: self[date(year, JUL, 24) + rd(days=-1)] = name + " (Observed)" elif self.observed and date(year, JUL, 24).weekday() == SUN: self[date(year, JUL, 24) + rd(days=+1)] = name + " (Observed)" # Constitution Day if self.state == "PR": self[date(year, JUL, 25)] = "Constitution Day" if self.observed and date(year, JUL, 25).weekday() == SUN: self[date(year, JUL, 26)] = "Constitution Day (Observed)" # Victory Day if self.state == "RI" and year >= 1948: self[date(year, AUG, 1) + rd(weekday=MO(+2))] = "Victory Day" # Statehood Day (Hawaii) if self.state == "HI" and year >= 1959: self[date(year, AUG, 1) + rd(weekday=FR(+3))] = "Statehood Day" # Bennington Battle Day if self.state == "VT" and year >= 1778: name = "Bennington Battle Day" self[date(year, AUG, 16)] = name if self.observed and date(year, AUG, 16).weekday() == SAT: self[date(year, AUG, 15)] = name + " (Observed)" elif self.observed and date(year, AUG, 16).weekday() == SUN: self[date(year, AUG, 17)] = name + " (Observed)" # Lyndon Baines Johnson Day if self.state == "TX" and year >= 1973: self[date(year, AUG, 27)] = "Lyndon Baines Johnson Day" # Labor Day if year >= 1894: self[date(year, SEP, 1) + rd(weekday=MO)] = "Labor Day" # Columbus Day if self.state not in ("AK", "AR", "DE", "FL", "HI", "NV"): if self.state == "SD": name = "Native American Day" elif self.state == "VI": name = "Columbus Day and Puerto Rico Friendship Day" else: name = "Columbus Day" if year >= 1970: self[date(year, OCT, 1) + rd(weekday=MO(+2))] = name elif year >= 1937: self[date(year, OCT, 12)] = name # Alaska Day if self.state == "AK" and year >= 1867: name = "Alaska Day" self[date(year, OCT, 18)] = name if self.observed and date(year, OCT, 18).weekday() == SAT: self[date(year, OCT, 18) + rd(days=-1)] = name + " (Observed)" elif self.observed and date(year, OCT, 18).weekday() == SUN: self[date(year, OCT, 18) + rd(days=+1)] = name + " (Observed)" # Nevada Day if self.state == "NV" and year >= 1933: dt = date(year, OCT, 31) if year >= 2000: dt += rd(weekday=FR(-1)) self[dt] = "Nevada Day" if self.observed and dt.weekday() == SAT: self[dt + rd(days=-1)] = "Nevada Day (Observed)" elif self.observed and dt.weekday() == SUN: self[dt + rd(days=+1)] = "Nevada Day (Observed)" # Liberty Day if self.state == "VI": self[date(year, NOV, 1)] = "Liberty Day" # Election Day if (self.state in ("DE", "HI", "IL", "IN", "LA", "MT", "NH", "NJ", "NY", "WV") and year >= 2008 and year % 2 == 0) or (self.state in ("IN", "NY") and year >= 2015): dt = date(year, NOV, 1) + rd(weekday=MO) self[dt + rd(days=+1)] = "Election Day" # All Souls' Day if self.state == "GU": self[date(year, NOV, 2)] = "All Souls' Day" # Veterans Day if year > 1953: name = "Veterans Day" else: name = "Armistice Day" if 1978 > year > 1970: self[date(year, OCT, 1) + rd(weekday=MO(+4))] = name elif year >= 1938: self[date(year, NOV, 11)] = name if self.observed and date(year, NOV, 11).weekday() == SAT: self[date(year, NOV, 11) + rd(days=-1)] = name + " (Observed)" elif self.observed and date(year, NOV, 11).weekday() == SUN: self[date(year, NOV, 11) + rd(days=+1)] = name + " (Observed)" # Discovery Day if self.state == "PR": self[date(year, NOV, 19)] = "Discovery Day" if self.observed and date(year, NOV, 19).weekday() == SUN: self[date(year, NOV, 20)] = "Discovery Day (Observed)" # Thanksgiving if year > 1870: self[date(year, NOV, 1) + rd(weekday=TH(+4))] = "Thanksgiving" # Day After Thanksgiving # Friday After Thanksgiving # Lincoln's Birthday # American Indian Heritage Day # Family Day # New Mexico Presidents' Day if ((self.state in ("CA", "DE", "FL", "NH", "NC", "OK", "TX", "WV") and year >= 1975) or (self.state == "IN" and year >= 2010) or (self.state == "MD" and year >= 2008) or self.state in ("NV", "NM")): if self.state in ("CA", "DE", "NH", "NC", "OK", "WV"): name = "Day After Thanksgiving" elif self.state in ("FL", "TX"): name = "Friday After Thanksgiving" elif self.state == "IN": name = "Lincoln's Birthday" elif self.state == "MD" and year >= 2008: name = "American Indian Heritage Day" elif self.state == "NV": name = "Family Day" elif self.state == "NM": name = "Presidents' Day" dt = date(year, NOV, 1) + rd(weekday=TH(+4)) self[dt + rd(days=+1)] = name # Robert E. Lee's Birthday if self.state == "GA" and year >= 1986: if year >= 2016: name = "State Holiday" else: name = "Robert E. Lee's Birthday" self[date(year, NOV, 29) + rd(weekday=FR(-1))] = name # Lady of Camarin Day if self.state == "GU": self[date(year, DEC, 8)] = "Lady of Camarin Day" # Christmas Eve if (self.state == "AS" or (self.state in ("KS", "MI", "NC") and year >= 2013) or (self.state == "TX" and year >= 1981) or (self.state == "WI" and year >= 2012)): name = "Christmas Eve" self[date(year, DEC, 24)] = name name = name + " (Observed)" # If on Friday, observed on Thursday if self.observed and date(year, DEC, 24).weekday() == FRI: self[date(year, DEC, 24) + rd(days=-1)] = name # If on Saturday or Sunday, observed on Friday elif self.observed and date(year, DEC, 24).weekday() in WEEKEND: self[date(year, DEC, 24) + rd(weekday=FR(-1))] = name # Christmas Day if year > 1870: name = "Christmas Day" self[date(year, DEC, 25)] = "Christmas Day" if self.observed and date(year, DEC, 25).weekday() == SAT: self[date(year, DEC, 25) + rd(days=-1)] = name + " (Observed)" elif self.observed and date(year, DEC, 25).weekday() == SUN: self[date(year, DEC, 25) + rd(days=+1)] = name + " (Observed)" # Day After Christmas if self.state == "NC" and year >= 2013: name = "Day After Christmas" self[date(year, DEC, 26)] = name name = name + " (Observed)" # If on Saturday or Sunday, observed on Monday if self.observed and date(year, DEC, 26).weekday() in WEEKEND: self[date(year, DEC, 26) + rd(weekday=MO)] = name # If on Monday, observed on Tuesday elif self.observed and date(year, DEC, 26).weekday() == MON: self[date(year, DEC, 26) + rd(days=+1)] = name elif self.state == "TX" and year >= 1981: self[date(year, DEC, 26)] = "Day After Christmas" elif self.state == "VI": self[date(year, DEC, 26)] = "Christmas Second Day" # New Year's Eve if (self.state in ("KY", "MI") and year >= 2013) or (self.state == "WI" and year >= 2012): name = "New Year's Eve" self[date(year, DEC, 31)] = name if self.observed and date(year, DEC, 31).weekday() == SAT: self[date(year, DEC, 30)] = name + " (Observed)"
# when, for no explicable reason, Wednesday was a half day instead). "Fridays after Independence Day that aren't in 2013", month=7, day=5, days_of_week=(FRIDAY, ), observance=july_5th_holiday_observance, start_date=Timestamp("1995-01-01"), ) USBlackFridayBefore1993 = Holiday( 'Black Friday', month=11, day=1, # Black Friday was not observed until 1992. start_date=Timestamp('1992-01-01'), end_date=Timestamp('1993-01-01'), offset=[DateOffset(weekday=TH(4)), Day(1)], ) USBlackFridayInOrAfter1993 = Holiday( 'Black Friday', month=11, day=1, start_date=Timestamp('1993-01-01'), offset=[DateOffset(weekday=TH(4)), Day(1)], ) BattleOfGettysburg = Holiday( # All of the floor traders in Chicago were sent to PA 'Markets were closed during the battle of Gettysburg', month=7, day=(1, 2, 3), start_date=Timestamp("1863-07-01"), end_date=Timestamp("1863-07-03"))
def _populate(self, year): # New Year's Day if not self.observed and date(year, JAN, 1).weekday() in WEEKEND: pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Carnival days # revisar este día para futuros casos name = "Día de Carnaval [Carnival's Day]" self[easter(year) - rd(days=48)] = name self[easter(year) - rd(days=47)] = name # Día de Reyes - Feriado en el cual se conmemora la llegada de # los reyes magos a Jesus if not self.observed and date(year, JAN, 6).weekday() in WEEKEND: pass else: self[date(year, JAN, 6)] = "Día de Reyes" # Holy Week name_thu = "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]" name_fri = "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]" name_easter = "Día de Pascuas [Easter Day]" self[easter(year) + rd(weekday=TH(-1))] = name_thu self[easter(year) + rd(weekday=FR(-1))] = name_fri if not self.observed and easter(year).weekday() in WEEKEND: pass else: self[easter(year)] = name_easter # Desembarco de los 33 Orientales en la playa de la Agraciada if not self.observed and date(year, APR, 19).weekday() in WEEKEND: pass else: self[date(year, APR, 19)] = ("Desembarco de los 33 Orientales " "Landing of the 33 Orientals" " Aterrissagem dos 33 Orientais" " Sbarco dei 33 orientali") # Día de los Trabajadores name = "Día del Trabajo [Labour Day]" if not self.observed and date(year, MAY, 1).weekday() in WEEKEND: pass else: self[date(year, MAY, 1)] = name # Batalla de las piedras name = "Batalla de las Piedras [Battle of the stones]" if not self.observed and date(year, MAY, 17).weekday() in WEEKEND: pass else: self[date(year, MAY, 17)] = name # Natalicio de José Gervacio Artigas name = "Natalicio de José Gervacio Artigas " if not self.observed and date(year, JUN, 19).weekday() in WEEKEND: pass else: self[date(year, JUN, 19)] = name # Jura de la Constitución name = "Jura de la constitución " if not self.observed and date(year, JUL, 18).weekday() in WEEKEND: pass else: self[date(year, JUL, 18)] = name # Declaratoria de la Independencia name = "Día de la Independencia [Independence Day]" if not self.observed and date(year, AUG, 25).weekday() in WEEKEND: pass else: self[date(year, AUG, 25)] = name # Respect for Cultural Diversity Day or Columbus day if not self.observed and date(year, OCT, 11).weekday() in WEEKEND: pass elif year < 2010: self[date(year, OCT, 11)] = "Día de la Raza [Columbus day]" else: self[date(year, OCT, 11)] = ("Día del Respeto a la Diversidad" " Cultural [Respect for" " Cultural Diversity Day]") # Día de los difuntos name = "Día de los difuntos" if not self.observed and date(year, NOV, 2).weekday() in WEEKEND: pass else: self[date(year, NOV, 2)] = name # Christmas self[date(year, DEC, 25)] = "Navidad [Christmas]"
def main(filePath): c = CurrencyConverter() today = date.today() mon = today + relativedelta(weekday=MO(-2)) #last MON tue = today + relativedelta(weekday=TU(-1)) #last TUE wed = today + relativedelta(weekday=WE(-1)) #last WED thu = today + relativedelta(weekday=TH(-1)) #last THU fri = today + relativedelta(weekday=FR(-1)) #last FRI sat = today + relativedelta(weekday=SA(-1)) #last SAT sun = today + relativedelta(weekday=SU(-1)) #last SUN weekArr = [mon,tue,wed,thu,fri,sat,sun] print("Executing for dates: ") for day in weekArr: print(day) print(day.strftime("%m")) countryArr = {"US": "ACCOUNT NAME"} print('loading XML dataframe...') dfXML = process_xml.main() print('loading adwords csv...') adwordsCSV = adwords_pull.get_raw_report() print('parsing adwords into dataframe...') dfCSV = csv_parser.parseToCSV(adwordsCSV,"ADW") print('parsing analytics into dataframe...') analyticsCSV = "" #pull for each day of the week - avoids data sampling this way but takes a bit longer #THIS NEEDS TO BE REFACTORED IN THE FUTURE for day in weekArr:# analyticsCSV += analytics_pull.main(str(day)) print("Pulled date: " + str(day)) dfAnalytics = csv_parser.parseToCSV(analyticsCSV,"ANL") dfAnalytics['date'] = dfAnalytics.apply(lambda row: CheckDateFormatAnalytics(row), axis=1) dfAnalytics = dfAnalytics[dfAnalytics.date != -1] #add month and Year to analytics dfAnalytics['monthNum'] = dfAnalytics.apply(lambda row: ApplyMonth(row,"ANL"), axis=1) dfAnalytics['yearNum'] = dfAnalytics.apply(lambda row: ApplyYear(row,"ANL"), axis=1) print("Done Processing APIs...") print("Processing Data...") dfXML['ID'] = dfXML['ID'].str.lower() dfCSV['GID'] = dfCSV['GID'].str.lower() dfXML['GID'] = dfXML['GID'].str.lower() dfCSV['OfferID'] = dfCSV['OfferID'].str.lower() #FILER US ONLY sql = f''' SELECT * FROM dfCSV WHERE dfCSV.Account = "{countryArr["US"]}" ''' dfCSV = pandasql.sqldf(sql, locals()) dfCSV['monthNum'] = dfCSV.apply(lambda row: ApplyMonth(row), axis=1) dfCSV['yearNum'] = dfCSV.apply(lambda row: ApplyYear(row), axis=1) #REMOVE THE SPACE AFTER THE GID GIDnew = [] for dfCSVIndex, dfCSVRow in dfCSV.iterrows(): newGID = dfCSVRow['GID'].partition(" ")[0] GIDnew.append(newGID) print(len(GIDnew)) print(dfCSV.shape) dfCSV=dfCSV.drop(columns="GID") dfCSV.loc[:,"GID"] = GIDnew print("processing csv to xml matches for linking table") #take the XML feed and the adwords report and EXACT match the OfferIDs together #ATTACH GTINS TO PRODUCTS # GOAL IS TO MATCH GTIN ON EVERY GROUP ID FROM ADWORDS # BEST WAY TO DO IT IS GROUP ADWORDS DF BY GID TO MAKE THE FILE SMALLER sqlGroupAdwords = ''' SELECT dfCSV.GID, SUM(dfCSV.Impressions) AS Impressions, SUM(dfCSV.Clicks) AS Clicks, SUM(dfCSV.Cost) AS Cost, SUM(dfCSV.ConversionValue) AS ConversionValue, dfCSV.monthNum as monthNum, dfCSV.yearNum as yearNum, dfCSV.Account as Account FROM dfCSV GROUP BY dfCSV.GID, dfCSV.Account, dfCSV.monthNum, dfCSV.yearNum ''' # DROP UNUSED DF dfCSV.iloc[0:0] # WRITE NEW DF adwordsGrpDF = pandasql.sqldf(sqlGroupAdwords, locals()) sql = ''' SELECT dfXML.GTIN as GTIN, dfXML.ID as ID, dfXML.GID as GID, dfXML.IMG as IMG, dfXML.BRAND as BRAND, adwordsGrpDF.monthNum as monthNum, adwordsGrpDF.yearNum as yearNum, adwordsGrpDF.Impressions as Impressions, adwordsGrpDF.Clicks as Clicks, adwordsGrpDF.ConversionValue as ConversionValue, adwordsGrpDF.Cost as Cost FROM dfXML, adwordsGrpDF WHERE dfXML.GID = adwordsGrpDF.GID ''' # DROP UNUSED DF adwordsGrpDF.iloc[0:0] dfXML.iloc[0:0] # WRITE NEW DF linkingTable = pandasql.sqldf(sql, locals()) print("-------XML AND ADWORDS MATCHED ON OfferID VIA SQL-------") print("-------LINKS GTIN TO THE OFFER ID === THEREFORE GTIN TO THE Adwords Metrics-------") #At this point the linkingTable DF holds the adwords stats and the gtin of the products #popular products CVS from import into df #imported CSV in dataframe form print('parsing imported CSV into dataframe...') print('----------------impoted CSV dataframe----------------') dfICSV = process_csv.main(filePath) #print(dfICSV) #match popular products with linkingTable dfICSV.rename(columns={'PopularityRank' : 'Pop'},inplace=True) #order by popularity dfICSV.sort_values(by=['Pop']) #TAKE THE FIRST 2000 RECORDS FROM THE POPULAR PRODUCTS CSV INTO A NEW DF - This can be any number between 0 and about 10k dfPopM = dfICSV[:2000] print("-----GET PRODUCTS THEY DONT SELL-----") sqlNotSold = ''' SELECT Pop, ChangeFromLastWeek, Title, GTIN, Brand, PriceRangeStart, PriceRangeEnd, WeekNumber FROM dfPopM WHERE ProductInventoryStatus = "Not in inventory" ORDER BY Pop ''' dfNotSold = pandasql.sqldf(sqlNotSold, locals()) #match popular products with linkingTable (adwords stats) count = 0 print("-----Processing matches-----") sql = ''' SELECT linkingTable.GID, linkingTable.Impressions, linkingTable.Cost, linkingTable.Clicks, linkingTable.ConversionValue, linkingTable.IMG, linkingTable.BRAND, linkingTable.monthNum, linkingTable.yearNum, dfPopM.Pop FROM linkingTable, dfPopM WHERE SUBSTR(linkingTable.GTIN,0,LENGTH(linkingTable.GTIN) - 1) = SUBSTR(dfPopM.GTIN,0,LENGTH(dfPopM.GTIN) - 3) ''' dfPopM.iloc[0:0] dfPopXmlMatch = pandasql.sqldf(sql, locals()) sqlGroupMatchTable = ''' SELECT dfPopXmlMatch.Pop, dfPopXmlMatch.GID FROM dfPopXmlMatch GROUP BY dfPopXmlMatch.Pop,dfPopXmlMatch.GID ''' dfPopXmlMatch = pandasql.sqldf(sqlGroupMatchTable, locals()) sqlMatchAll = ''' SELECT linkingTable.GID, linkingTable.Impressions, linkingTable.Cost, linkingTable.Clicks, linkingTable.ConversionValue, linkingTable.IMG, linkingTable.BRAND, linkingTable.monthNum, linkingTable.yearNum, dfPopXmlMatch.Pop FROM linkingTable, dfPopXmlMatch WHERE dfPopXmlMatch.GID = linkingTable.GID GROUP BY linkingTable.GID, linkingTable.Impressions, linkingTable.Cost, linkingTable.Clicks, linkingTable.ConversionValue, linkingTable.IMG, linkingTable.monthNum, linkingTable.yearNum, dfPopXmlMatch.Pop ''' linkingTable.iloc[0:0] dfPopXmlMatch = pandasql.sqldf(sqlMatchAll, locals()) #group the results by date and IDNew while adding the metrics together sqlGroup = ''' SELECT dfPopXmlMatch.GID as GID, SUM(dfPopXmlMatch.Impressions) as Impressions, SUM(dfPopXmlMatch.Cost) as Cost, SUM(dfPopXmlMatch.Clicks) as Clicks, SUM(dfPopXmlMatch.ConversionValue) as ConversionValue, dfPopXmlMatch.IMG as IMG, dfPopXmlMatch.BRAND as BRAND, dfPopXmlMatch.monthNum as monthNum, dfPopXmlMatch.yearNum as yearNum, dfPopXmlMatch.Pop FROM dfPopXmlMatch GROUP BY dfPopXmlMatch.GID, dfPopXmlMatch.IMG, dfPopXmlMatch.Pop, dfPopXmlMatch.monthNum , dfPopXmlMatch.yearNum ''' dfPopXmlMatch = pandasql.sqldf(sqlGroup, locals()) print('---------GROUPED THE ABOVE---------') sqlGroupAnalytics = ''' SELECT dfAnalytics.productName as productName, dfAnalytics.productSku as productSku, dfAnalytics.country as country, dfAnalytics.monthNum as monthNum, dfAnalytics.yearNum as yearNum, SUM(dfAnalytics.itemRevenue) as itemRevenue, AVG(dfAnalytics.buyToDetailRate) as buyToDetailRate FROM dfAnalytics WHERE dfAnalytics.country = "United States" GROUP BY dfAnalytics.country, dfAnalytics.productSku, dfAnalytics.productName, dfAnalytics.monthNum , dfAnalytics.yearNum ''' dfAnalytics = pandasql.sqldf(sqlGroupAnalytics, locals()) sql = ''' SELECT dfPopXmlMatch.GID as ID, dfPopXmlMatch.Impressions as Impressions, dfPopXmlMatch.Cost as Cost, dfPopXmlMatch.Clicks as Clicks, dfPopXmlMatch.ConversionValue as ConversionValue, dfPopXmlMatch.IMG as IMG, dfPopXmlMatch.BRAND as BRAND, dfPopXmlMatch.Pop as Pop, dfAnalytics.itemRevenue as itemRev, dfAnalytics.buyToDetailRate as buyToDetailRate, dfAnalytics.productName as productName, dfAnalytics.country as country, dfAnalytics.monthNum as monthNum, dfAnalytics.yearNum as yearNum FROM dfPopXmlMatch, dfAnalytics WHERE LOWER(dfPopXmlMatch.GID) = LOWER(dfAnalytics.productSku) AND dfAnalytics.monthNum = dfPopXmlMatch.monthNum AND dfAnalytics.yearNum = dfPopXmlMatch.yearNum ''' dfPopXmlMatch.iloc[0:0] dfFinal = pandasql.sqldf(sql, locals()) ######### currency converting start ######### #COMMENT OUT THE BELOW IF YOU DONT NEED TO CONVER CURRENCY - MORE EFFICIENT WAY IN product_sizes.py - make into method in futurre updates newCost = [] newROAS = [] for dfFinalIndex, dfFinalRow in dfFinal.iterrows(): newVal = c.convert(dfFinalRow['Cost'] / 1000000, 'USD', 'YOUR_CURRENCY') newCost.append(newVal) if float(newVal) <= 0: newROAS.append(0) else: newROAS.append(float(dfFinalRow['itemRev']) / float(newVal)) dfFinal.loc[:,"newCost"] = newCost dfFinal.loc[:,"newROAS"] = newROAS ######### currency converting end ######### #add a new column to df and fill it with the above week number weekNo = int(mon.strftime("%W")) + 1 dfFinal["WeekNumber"] = str(weekNo) #if not string, data studio gives an error print("Processing Complete...") #Products they dont sell dfNotSold dfNotSold.to_gbq('DATASET_NAME.TABLE_NAME', project_id='YOUR_PROJECT_ID', chunksize=None, if_exists='append', table_schema=None, location='LOCATION', progress_bar=True, credentials=google_auth.getCreds()) #linked table with what they have sold dfFinal dfFinal.to_gbq('DATASET_NAME.TABLE_NAME', #TABLE_NAME here is refered to as CLIENT_DO_SELL in the SQL files project_id='YOUR_PROJECT_ID', chunksize=None, if_exists='append', table_schema=None, location='LOCATION', progress_bar=True, credentials=google_auth.getCreds()) #the csv from google mc dfICSV = dfICSV[:2000] #clip it if needed here dfICSV.to_gbq('DATASET_NAME.TABLE_NAME', project_id='YOUR_PROJECT_ID', chunksize=None, if_exists='append', table_schema=None, location='LOCATION', progress_bar=True, credentials=google_auth.getCreds()) dfFinal.iloc[0:0] dfICSV.iloc[0:0]
def make_time_features(ts, index=None, epoch=None, epoch_span=None): """Project datetimes into vector space for use in machine learning models Outputs: - projection onto the unit circle of - second of day - day of week - day of year - seconds since `epoch`, normalized by `epoch_span` - binary workday indicator (i.e., Monday-Friday except major US holidays) :param ts: timestamp(s) to process :type ts: datetime.datetime or iterable thereof :param index: index of ts (e.g., if from a larger dataframe) :param epoch: start of time reckoning :param epoch_span: length of time reckoning :rtype: pd.DataFrame :returns: various projections of datetimes into vector space """ # input validation try: if len(ts) == 1: _singleton = True elif len(ts) > 1: _singleton = False elif len(ts) < 1: raise ValueError("must pass non-empty iterable of timestamps") except TypeError: return make_time_features([ts], index=index, epoch=epoch, epoch_span=epoch_span) if not isinstance(ts, pd.DatetimeIndex): ts = pd.Series(0, index=ts).index if not isinstance(ts, pd.DatetimeIndex): raise ValueError("must pass non-empty iterable of timestamps") if index is None: index = pd.RangeIndex(len(ts)) if epoch is None: epoch = min(ts) if epoch_span is None: epoch_span = float((end - epoch).total_seconds()) time_features = {} start = min(ts) end = max(ts) # Major US holidays NewYearsDay = pd.tseries.holiday.Holiday('New Years Day', month=1, day=1) MemorialDay = pd.tseries.holiday.Holiday('Memorial Day', month=6, day=1, offset=pd.DateOffset(weekday=MO(-1))) IndependenceDay = pd.tseries.holiday.Holiday('Independence Day', month=7, day=4) LaborDay = pd.tseries.holiday.Holiday('Labor Day', month=9, day=1, offset=pd.DateOffset(weekday=MO(1))) ThanksgivingDay = pd.tseries.holiday.Holiday('Thanksgiving Day', month=11, day=1, offset=pd.DateOffset(weekday=TH(4))) ChristmasDay = pd.tseries.holiday.Holiday('Christmas Day', month=12, day=25) holidays = \ NewYearsDay.dates(start.date(), end.date()).tolist() +\ MemorialDay.dates(start.date(), end.date()).tolist() +\ IndependenceDay.dates(start.date(), end.date()).tolist() +\ LaborDay.dates(start.date(), end.date()).tolist() +\ ThanksgivingDay.dates(start.date(), end.date()).tolist() +\ ChristmasDay.dates(start.date(), end.date()).tolist() holidays = set([h.date() for h in holidays]) # projections onto unit circle time_features['day_cos'] = np.cos((ts.hour * 3600 + ts.minute * 60 + ts.second) * 2 * np.pi / 86400.) time_features['day_sin'] = np.sin((ts.hour * 3600 + ts.minute * 60 + ts.second) * 2 * np.pi / 86400.) time_features['week_cos'] = np.cos(ts.dayofweek * 2 * np.pi / 7.) time_features['week_sin'] = np.sin(ts.dayofweek * 2 * np.pi / 7.) time_features['year_cos'] = np.cos(ts.dayofyear * 2 * np.pi / 365.) time_features['year_sin'] = np.sin(ts.dayofyear * 2 * np.pi / 365.) # linear march through time time_features['epoch'] = (ts - epoch).total_seconds() / epoch_span # workday indicator time_features['workday'] = [int(weekday < 5 and date not in holidays) for weekday, date in zip(ts.weekday, ts.date)] if _singleton: return {k: v[0] for k, v in time_features.iteritems()} else: return pd.DataFrame(time_features, index=index)
) USPresidentsDay = Holiday( "President's Day", start_date=Timestamp("1971-01-01"), month=2, day=1, offset=DateOffset(weekday=MO(3)), ) USThanksgivingDayBefore1939 = Holiday( "Thanksgiving Before 1939", start_date=Timestamp("1864-01-01"), end_date=Timestamp("1938-12-31"), month=11, day=30, offset=DateOffset(weekday=TH(-1)), ) USThanksgivingDay1939to1941 = Holiday( "Thanksgiving 1939 to 1941", start_date=Timestamp("1939-01-01"), end_date=Timestamp("1941-12-31"), month=11, day=30, offset=DateOffset(weekday=TH(-2)), ) USThanksgivingDay = Holiday( "Thanksgiving", start_date=Timestamp("1942-01-01"), month=11, day=1,
def _populate(self, year): # New Year's Day if not self.observed and date(year, JAN, 1).weekday() in WEEKEND: pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Carnival days name = "Día de Carnaval [Carnival's Day]" self[easter(year) - rd(days=48)] = name self[easter(year) - rd(days=47)] = name # Memory's National Day for the Truth and Justice name = "Día Nacional de la Memoria por la Verdad y la Justicia " \ "[Memory's National Day for the Truth and Justice]" if not self.observed and date(year, MAR, 24).weekday() in WEEKEND: pass else: self[date(year, MAR, 24)] = name # Holy Week name_thu = "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]" name_fri = "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]" name_easter = 'Día de Pascuas [Easter Day]' self[easter(year) + rd(weekday=TH(-1))] = name_thu self[easter(year) + rd(weekday=FR(-1))] = name_fri if not self.observed and easter(year).weekday() in WEEKEND: pass else: self[easter(year)] = name_easter # Veterans Day and the Fallen in the Malvinas War if not self.observed and date(year, APR, 2).weekday() in WEEKEND: pass else: self[date(year, APR, 2)] = "Día del Veterano y de los Caidos " \ "en la Guerra de Malvinas [Veterans" \ " Day and the Fallen in the" \ " Malvinas War]" # Labor Day name = "Día del Trabajo [Labour Day]" if not self.observed and date(year, MAY, 1).weekday() in WEEKEND: pass else: self[date(year, MAY, 1)] = name # May Revolution Day name = "Día de la Revolucion de Mayo [May Revolution Day]" if not self.observed and date(year, MAY, 25).weekday() in WEEKEND: pass else: self[date(year, MAY, 25)] = name # Day Pass to the Immortality of General Martín Miguel de Güemes. name = "Día Pase a la Inmortalidad " \ "del General Martín Miguel de Güemes [Day Pass " \ "to the Immortality of General Martín Miguel de Güemes]" if not self.observed and date(year, JUN, 17).weekday() in WEEKEND: pass else: self[date(year, JUN, 17)] = name # Day Pass to the Immortality of General D. Manuel Belgrano. name = "Día Pase a la Inmortalidad " \ "del General D. Manuel Belgrano [Day Pass " \ "to the Immortality of General D. Manuel Belgrano]" if not self.observed and date(year, JUN, 20).weekday() in WEEKEND: pass else: self[date(year, JUN, 20)] = name # Independence Day name = "Día de la Independencia [Independence Day]" if not self.observed and date(year, JUL, 9).weekday() in WEEKEND: pass else: self[date(year, JUL, 9)] = name # Day Pass to the Immortality of General D. José de San Martin name = "Día Pase a la Inmortalidad " \ "del General D. José de San Martin [Day Pass " \ "to the Immortality of General D. José de San Martin]" if not self.observed and date(year, AUG, 17).weekday() in WEEKEND: pass else: self[date(year, AUG, 17)] = name # Respect for Cultural Diversity Day or Columbus day if not self.observed and date(year, OCT, 12).weekday() in WEEKEND: pass elif year < 2010: self[date(year, OCT, 12)] = "Día de la Raza [Columbus day]" else: self[date(year, OCT, 12)] = "Día del Respeto a la Diversidad" \ " Cultural [Respect for" \ " Cultural Diversity Day]" # National Sovereignty Day name = "Día Nacional de la Soberanía [National Sovereignty Day]" if not self.observed and date(year, NOV, 20).weekday() in WEEKEND: pass elif year >= 2010: self[date(year, NOV, 20)] = name # Immaculate Conception if not self.observed and date(year, DEC, 8).weekday() in WEEKEND: pass else: self[date(year, DEC, 8)] = "La Inmaculada Concepción" \ " [Immaculate Conception]" # Christmas self[date(year, DEC, 25)] = "Navidad [Christmas]"
def _populate(self, year): # New Year's Day if not self.observed and date(year, JAN, 1).weekday() in WEEKEND: pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Patriots day name = "Día de los Héroes de la Patria" \ "[Patriots Day]" if not self.observed and date(year, MAR, 1).weekday() in WEEKEND: pass elif date(year, MAR, 1).weekday() >= WED: self[date(year, MAR, 1) + rd(weekday=MO(+1))] = name else: self[date(year, MAR, 1)] = name # Holy Week name_thu = "Semana Santa (Jueves Santo) [Holy day (Holy Thursday)]" name_fri = "Semana Santa (Viernes Santo) [Holy day (Holy Friday)]" name_easter = 'Día de Pascuas [Easter Day]' self[easter(year) + rd(weekday=TH(-1))] = name_thu self[easter(year) + rd(weekday=FR(-1))] = name_fri if not self.observed and easter(year).weekday() in WEEKEND: pass else: self[easter(year)] = name_easter # Labor Day name = "Día de los Trabajadores [Labour Day]" if not self.observed and date(year, MAY, 1).weekday() in WEEKEND: pass else: self[date(year, MAY, 1)] = name # Independence Day name = "Día de la Independencia Nacional [Independence Day]" if not self.observed and date(year, MAY, 15).weekday() in WEEKEND: pass else: self[date(year, MAY, 15)] = name # Peace in Chaco Day. name = "Día de la Paz del Chaco [Peace in Chaco Day]" if not self.observed and date(year, JUN, 12).weekday() in WEEKEND: pass elif date(year, JUN, 12).weekday() >= WED: self[date(year, JUN, 12) + rd(weekday=MO(+1))] = name else: self[date(year, JUN, 12)] = name # Asuncion Fundation's Day name = "Día de la Fundación de Asunción [Asuncion Fundation's Day]" if not self.observed and date(year, AUG, 15).weekday() in WEEKEND: pass else: self[date(year, AUG, 15)] = name # Boqueron's Battle name = "Batalla de Boquerón [Boqueron's Battle]" if not self.observed and date(year, SEP, 29).weekday() in WEEKEND: pass else: self[date(year, SEP, 29)] = name # Caacupe Virgin Day name = "Día de la Virgen de Caacupé [Caacupe Virgin Day]" if not self.observed and date(year, DEC, 8).weekday() in WEEKEND: pass else: self[date(year, DEC, 8)] = name # Christmas self[date(year, DEC, 25)] = "Navidad [Christmas]"
def get_last_thrusday(Date): from dateutil.relativedelta import relativedelta, TH return Date + relativedelta(day=31, weekday=TH(-1))
from datetime import date from dateutil.relativedelta import relativedelta, TH format = "%Y-%m-%d" today = date.today() sunday = today + relativedelta(weekday=TH(-1)) date = sunday.strftime(format) print(date)
""" equinox = ephem.next_spring_equinox(str(dt.year)).datetime().date() return obs_sunday_drop_sunday(Timestamp(equinox)) def compute_autumnal_equinox_obs(dt): """ computes autumnal equinox and observes using weekend_to_monday """ equinox = ephem.next_autumnal_equinox(str(dt.year)).datetime().date() return obs_sunday_drop_sunday(Timestamp(equinox)) AfterUSThanksgiving = Holiday('Thanksgiving', month=11, day=1, offset=[DateOffset(weekday=TH(4)), Day(1)]) CAThanksgivingDay = Holiday('Thanksgiving', month=10, day=1, offset=DateOffset(weekday=MO(2))) NewYears = Holiday('New Years Day', month=1, day=1, observance=obs_sunday_drop_sunday) NewYearsEve = Holiday('New Years Eve', month=1, day=1, observance=obs_sunday_drop_sunday, offset=BDay(-1))
def _populate(self, year): # Fixed date holidays! # If observed=True and they fall on a weekend they are not observed. # If observed=False there are 18 holidays # New Year's Day if self.observed and date(year, JAN, 1).weekday() in WEEKEND: pass else: self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]" # Labor Day self[date(year, MAY, 1)] = "Día del Trabajo [Labour Day]" # Independence Day name = "Día de la Independencia [Independence Day]" if self.observed and date(year, JUL, 20).weekday() in WEEKEND: pass else: self[date(year, JUL, 20)] = name # Battle of Boyaca self[date(year, AUG, 7)] = "Batalla de Boyacá [Battle of Boyacá]" # Immaculate Conception if self.observed and date(year, DEC, 8).weekday() in WEEKEND: pass else: self[date(year, DEC, 8)] = ( "La Inmaculada Concepción" " [Immaculate Conception]" ) # Christmas self[date(year, DEC, 25)] = "Navidad [Christmas]" # Emiliani Law holidays! # Unless they fall on a Monday they are observed the following monday # Epiphany name = "Día de los Reyes Magos [Epiphany]" if date(year, JAN, 6).weekday() == MON or not self.observed: self[date(year, JAN, 6)] = name else: self[date(year, JAN, 6) + rd(weekday=MO)] = name + "(Observed)" # Saint Joseph's Day name = "Día de San José [Saint Joseph's Day]" if date(year, MAR, 19).weekday() == MON or not self.observed: self[date(year, MAR, 19)] = name else: self[date(year, MAR, 19) + rd(weekday=MO)] = name + "(Observed)" # Saint Peter and Saint Paul's Day name = "San Pedro y San Pablo [Saint Peter and Saint Paul]" if date(year, JUN, 29).weekday() == MON or not self.observed: self[date(year, JUN, 29)] = name else: self[date(year, JUN, 29) + rd(weekday=MO)] = name + "(Observed)" # Assumption of Mary name = "La Asunción [Assumption of Mary]" if date(year, AUG, 15).weekday() == MON or not self.observed: self[date(year, AUG, 15)] = name else: self[date(year, AUG, 15) + rd(weekday=MO)] = name + "(Observed)" # Discovery of America name = "Descubrimiento de América [Discovery of America]" if date(year, OCT, 12).weekday() == MON or not self.observed: self[date(year, OCT, 12)] = name else: self[date(year, OCT, 12) + rd(weekday=MO)] = name + "(Observed)" # All Saints’ Day name = "Dia de Todos los Santos [All Saint's Day]" if date(year, NOV, 1).weekday() == MON or not self.observed: self[date(year, NOV, 1)] = name else: self[date(year, NOV, 1) + rd(weekday=MO)] = name + "(Observed)" # Independence of Cartagena name = "Independencia de Cartagena [Independence of Cartagena]" if date(year, NOV, 11).weekday() == MON or not self.observed: self[date(year, NOV, 11)] = name else: self[date(year, NOV, 11) + rd(weekday=MO)] = name + "(Observed)" # Holidays based on Easter # Maundy Thursday self[easter(year) + rd(weekday=TH(-1))] = "Jueves Santo [Maundy Thursday]" # Good Friday self[easter(year) + rd(weekday=FR(-1))] = "Viernes Santo [Good Friday]" # Holidays based on Easter but are observed the following monday # (unless they occur on a monday) # Ascension of Jesus name = "Ascensión del señor [Ascension of Jesus]" hdate = easter(year) + rd(days=+39) if hdate.weekday() == MON or not self.observed: self[hdate] = name else: self[hdate + rd(weekday=MO)] = name + "(Observed)" # Corpus Christi name = "Corpus Christi [Corpus Christi]" hdate = easter(year) + rd(days=+60) if hdate.weekday() == MON or not self.observed: self[hdate] = name else: self[hdate + rd(weekday=MO)] = name + "(Observed)" # Sacred Heart name = "Sagrado Corazón [Sacred Heart]" hdate = easter(year) + rd(days=+68) if hdate.weekday() == MON or not self.observed: self[hdate] = name else: self[hdate + rd(weekday=MO)] = name + "(Observed)"
def handle(self) -> date: return self.result + relativedelta(weekday=TH(self.number))
# This file contains all the functions that the workflow # uses for specialised dates. from math import floor from arrow.arrow import datetime, timedelta # The DAY_MAP is specific to relative delta from date_format_mappings import DATE_MAPPINGS, TIME_MAPPINGS, DATE_TIME_MAPPINGS from dateutil.relativedelta import relativedelta, MO, TU, WE, TH, FR, SA, SU from dateutil.rrule import rrule, YEARLY, DAILY DAY_MAP = { "mon": relativedelta(days=+1, weekday=MO(+1)), "tue": relativedelta(days=+1, weekday=TU(+1)), "wed": relativedelta(days=+1, weekday=WE(+1)), "thu": relativedelta(days=+1, weekday=TH(+1)), "fri": relativedelta(days=+1, weekday=FR(+1)), "sat": relativedelta(days=+1, weekday=SA(+1)), "sun": relativedelta(days=+1, weekday=SU(+1)), "prev mon": relativedelta(days=-1, weekday=MO(-1)), "prev tue": relativedelta(days=-1, weekday=TU(-1)), "prev wed": relativedelta(days=-1, weekday=WE(-1)), "prev thu": relativedelta(days=-1, weekday=TH(-1)), "prev fri": relativedelta(days=-1, weekday=FR(-1)), "prev sat": relativedelta(days=-1, weekday=SA(-1)), "prev sun": relativedelta(days=-1, weekday=SU(-1)), } DAYS_OF_WEEK_ABBREVIATIONS = { "mon": "monday", "tue": "tuesday", "wed": "wednesday",
import requests, json import pandas as pd from datetime import datetime from dateutil.relativedelta import relativedelta, TH #def nextThu_and_lastThu_expiry_date (): todayte = datetime.today() cmon = todayte.month if_month_next = (todayte + relativedelta(weekday=TH(1))).month next_thursday_expiry = todayte + relativedelta( weekday=TH(2)) #replace 2 to 1 to get current week expiry date if (if_month_next != cmon): month_last_thu_expiry = todayte + relativedelta(weekday=TH(5)) if (month_last_thu_expiry.month != if_month_next): month_last_thu_expiry = todayte + relativedelta(weekday=TH(4)) else: for i in range(1, 7): t = todayte + relativedelta(weekday=TH(i)) if t.month != cmon: # since t is exceeded we need last one which we can get by subtracting -2 since it is already a Thursday. t = t + relativedelta(weekday=TH(-2)) month_last_thu_expiry = t break str_month_last_thu_expiry = str(int( month_last_thu_expiry.strftime("%d"))) + month_last_thu_expiry.strftime( "%b").upper() + month_last_thu_expiry.strftime("%Y") str_next_thursday_expiry = str(int( next_thursday_expiry.strftime("%d"))) + next_thursday_expiry.strftime(
PC = PortConst() SAA = SA() SS = SecS() I = IPO() N.Analyst_history() print("analyst_history_updated") DC.Tradingday() DC.Dailyreturn_Update_Daily() dailyreturn = DC.Dailyreturn_retrieve() lasttradingday = dailyreturn['date'].max() rebalday = [str(lasttradingday)[0:10]] today = date.today() if datetime.datetime.today().weekday() >= 3: thursday = today + relativedelta(weekday=TH(-2)) else: thursday = today + relativedelta(weekday=TH(-1)) thursday = [str(thursday.strftime("%Y-%m-%d"))] todayname = str(today.strftime("%Y-%m-%d")) thursday = ['2021-01-21'] #facdict={'Quality': ['ROETTM', 'ROATTM','GrossIncomeRatioTTM'],'Growth': ['QRevenuegrowth', 'QNetprofitgrowth'],'Value': ['PE', 'PB', 'PS']} def DailyUpdate(dailyreturn, rebalday): facdict = { 'Quality': ['ROETTM', 'ROATTM', 'GrossIncomeRatioTTM'], 'Growth': ['QRevenuegrowth', 'QNetprofitgrowth'], 'Value': ['PE', 'PB', 'PS'] } selectsigs = []
USMemorialDay = Holiday("Memorial Day", month=5, day=31, offset=DateOffset(weekday=MO(-1))) USLaborDay = Holiday("Labor Day", month=9, day=1, offset=DateOffset(weekday=MO(1))) USColumbusDay = Holiday("Columbus Day", month=10, day=1, offset=DateOffset(weekday=MO(2))) USThanksgivingDay = Holiday("Thanksgiving", month=11, day=1, offset=DateOffset(weekday=TH(4))) USMartinLutherKingJr = Holiday( "Martin Luther King Jr. Day", start_date=datetime(1986, 1, 1), month=1, day=1, offset=DateOffset(weekday=MO(3)), ) USPresidentsDay = Holiday("Presidents Day", month=2, day=1, offset=DateOffset(weekday=MO(3))) GoodFriday = Holiday("Good Friday", month=1, day=1, offset=[Easter(), Day(-2)]) EasterMonday = Holiday("Easter Monday", month=1,
def _get_start_of(self, span): if span == 'week': user_lang = self.env['res.lang'].search([('code', '=', self.env.user.lang)]) week_start_map = {'1': MO(-1), '2': TU(-1), '3': WE(-1), '4': TH(-1), '5': FR(-1), '6': SA(-1), '7': SU(-1)} return relativedelta(weekday=week_start_map.get(user_lang.week_start, MO(-1))) return START_OF[span]