def image_from_instance(instance_name, no_reboot=True): conn = get_ec2_con() instance = get_instance(instance_name) if len(instance.groups) == 1: group = instance.groups[0].name else: print "Instance belongs to multiple security groups: {}".format( [g.name for g in instance.groups]) group = raw_input("enter category for image: ").strip() name = "{group} {date}".format(group=group, date=local_date()) description = "image generated by newhive.manage.ec2.image_from_instance from server {name} on {date}" description = description.format(name=server_name, date=local_date()) image_id = conn.create_image(instance.id, name, description, no_reboot) image = None while not image: time.sleep(0.5) try: image = conn.get_image(image_id) except conn.ResponseError: print "retrying" image = None image.add_tag('Name', name) image.add_tag('category', group) image.add_tag('created', int(now())) return image
def summary(db): data = queries.GASummary().execute(local_date(-1)).dataframe data.index = data.index.map(lambda x: x.date()) data.columns = data.columns.map(ga_column_name_to_title) data['Returning Visits'] = data['Visits'] - data['New Visits'] q = queries.Active(db) for period in [1,7,30]: active = q.execute(period) active.index = active.index.map(lambda x: x.date()) data = data.join(active) for q in [queries.UsersPerDay, queries.LovesPerDay, queries.ListensPerDay, queries.ExpressionsCreatedPerDay]: per_day = q(db).execute() data = data.join(per_day) data["DAU/MAU"] = data["Active1"] / data["Active30"] new = data["New Users Per Day"] #data["DAU/MAU'"] = (data["Active1"] - new) / ( data["Active30"] - new) data = data[data.index < local_date()] today = data.ix[local_date(-1)] previous = data.ix[[-2, -8, -29]] previous.index = ['DoD', 'WoW', 'MoM'] change = today.map(float) / previous - 1 return {'today': today, 'change': change}
def _execute(self): q = GAQuery()\ .start_date( min_start_date )\ .end_date( local_date() )\ .metrics( ['ga:visits'] )\ .dimensions( ['ga:date', 'ga:customVarValue1'] ) return q.execute()
def _execute(self, date): if date >= local_date(): logger.warn('running GASummary on unfinished day') q = GAQuery(dimensions=['ga:date'], metrics=['ga:visitors', 'ga:visits', 'ga:newVisits']) q.end_date(date) q.start_date(min_start_date) return q.execute()
def send(self, address): self.recipient = {'email': address, 'name': 'Team'} context = { 'summary': analytics.summary(self.db), 'link': AbsUrl('analytics/dashboard'), 'date': utils.local_date(-1) } self.send_mail(context)
def _active_users_ga(db, period=7): """Return users present in GA logs in last 'period' days""" tz = pytz.timezone('US/Pacific') end_date = datetime.datetime.now(tz) - pandas.DateOffset(days=1) end_date = local_date() start_date = end_date - pandas.DateOffset(days=period-1) query = GAQuery(start_date=start_date, end_date=end_date) query.metrics(['ga:visits']).dimensions(['ga:customVarValue1']) names = [row[0] for row in query.execute().rows] return db.User.search({'name': {'$in': names}})