Ejemplo n.º 1
0
def main(driver, startdate, enddate, statuslabel, report):
    locationstruct = PIEdataVARS.locations
    locationstruct.endDate = enddate
    locationstruct.startDate = startdate
    locationurl = locationstruct.urlList()
    locationframe = PieHandler.goandget(driver, locationurl, locationstruct)
    locationframe['staffed_minutes'] = vectorize(functions.getMinutes)(
        locationframe['assumedDuration-difference'])
    locationframe['abb'] = locationframe['location-shortName'].apply(
        lambda x: functions.getAbb(x))
    locationframe = locationframe.groupby(
        'abb')['staffed_minutes'].median().reset_index()

    report.add('table', 'Median Stepout Times', locationframe)
    report.makeHTML('Stepout Medians')
Ejemplo n.º 2
0
def main(driver, startdate, enddate, statuslabel, report):
    activeuserstruct = PIEdataVARS.activerusers
    urllist = activeuserstruct.urlList()
    userframe = PieHandler.goandget(driver, urllist, activeuserstruct)

    searchlist = [
        'address', 'emergencyName', 'emergencyRelationship',
        'emergencyPhoneNumber', 'phone'
    ]

    missinghold = []

    for index, row in userframe.iterrows():
        temparray = []
        if yikescheck(row['address']):
            temparray.append('address')
        if yikescheck(row['emergencyName']):
            temparray.append('emergencyName')
        if yikescheck(row['emergencyRelationship']):
            temparray.append('emergencyRelationship')
        if yikescheck(row['emergencyPhoneNumber']):
            temparray.append('emergencyPhoneNumber')
        if yikescheck(row['phoneNumber']):
            temparray.append('phoneNumber')

        missinghold.append(temparray)

    se = Series(missinghold)
    userframe['Missing Attributes'] = se.values

    userframe = userframe[[
        'lastName', 'firstName', 'username', 'Missing Attributes'
    ]]

    report.add('table', 'Missing User Info', userframe)

    report.makeHTML('Missing User Info')
Ejemplo n.º 3
0
def main(driver, startdate, enddate, statuslabel, report):

    # okay so take active users and then do an individual query for each one on assigned badges oh gosh okay also select columns
    # so that we don't nuke the memory probably. BREAK

    #lets grab active users
    activeusers = PIEdataVARS.activerusers
    urllist = activeusers.urlList()
    ids = PieHandler.goandget(driver, urllist, activeusers)['id'].tolist()

    # find badges for each user and scooby doo them together
    badges = PIEdataVARS.assignedbadges

    frames = []

    for id in ids:
        url = [badges.link + '&userId=' + str(id)]
        print(url)
        frame = PieHandler.goandget(driver, url, badges)
        if frame is not False:
            if 'assignedBy-username' not in frame:
                frame['assignedBy-username'] = ''
            if 'badge-assignedBy' not in frame:
                frame['badge-assignedBy'] = ''
            frame = frame[[
                'user-username', 'assignedBy-username', 'badge-assignedBy',
                'badge-badgeCategory-description', 'badge-name', 'created',
                'user-lastName', 'user-firstName'
            ]]
            frames.append(frame)

    bigo = concat(frames)
    bigo['created'] = bigo['created'].astype(str).str[:-6]
    bigo['created'] = to_datetime(bigo['created'])
    bigo[
        'user-username'] = bigo['user-firstName'] + ' ' + bigo['user-lastName']

    bigo = bigo.sort_values(['user-username', 'badge-name', 'created'],
                            ascending=(True, True, True))

    # find number of badges total
    totalnum = bigo[['user-username',
                     'badge-name']].groupby(['user-username']).count()
    totalnum.rename(columns={totalnum.columns[0]: "total badges"},
                    inplace=True)

    # total unique badges
    totalunique = bigo[['user-username', 'badge-name', 'created']].groupby([
        'user-username', 'badge-name'
    ]).count().reset_index().groupby(['user-username']).count()
    totalunique.rename(columns={totalunique.columns[0]: "total unique badges"},
                       inplace=True)

    #find total badges received in period
    startdate = datetime.datetime.combine(startdate,
                                          datetime.datetime.min.time())
    enddate = datetime.datetime.combine(enddate, datetime.datetime.min.time())
    totalnew = bigo[(bigo['created'] > startdate)
                    & (bigo['created'] < enddate)]
    totalnew = totalnew[['user-username',
                         'badge-name']].groupby(['user-username']).count()
    totalnew.rename(columns={totalnew.columns[0]: "badges in period"},
                    inplace=True)

    #first time badges this month
    firsts = bigo[['user-username', 'badge-name',
                   'created']].groupby(['user-username', 'badge-name'
                                        ]).agg({'created': 'first'})
    firsts = firsts[(firsts['created'] > startdate)
                    & (firsts['created'] < enddate)]
    firsts = firsts.groupby(['user-username']).count()
    firsts.rename(columns={firsts.columns[0]: "first time badges in period"},
                  inplace=True)

    merged = merge(totalnum,
                   totalunique,
                   left_index=True,
                   right_index=True,
                   how='left')
    merged = merge(merged,
                   totalnew,
                   left_index=True,
                   right_index=True,
                   how='left')
    merged = merge(merged,
                   firsts,
                   left_index=True,
                   right_index=True,
                   how='left').reset_index()
    merged.rename(columns={merged.columns[0]: "user"}, inplace=True)
    merged.drop(['created'], axis=1, inplace=True)

    merged.sort_values(['total badges'],
                       inplace=True,
                       ascending=True,
                       na_position='first')

    plt.tight_layout()
    merged.plot(x='user',
                y='total badges',
                kind='barh',
                figsize=(8, 10),
                zorder=2,
                width=0.85)
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\totalbadges.png')
    report.add('graph', 'Total Badges', '\\totalbadges.png')

    merged.sort_values(['total unique badges'],
                       inplace=True,
                       ascending=True,
                       na_position='first')

    plt.tight_layout()
    merged.plot(x='user',
                y='total unique badges',
                kind='barh',
                figsize=(8, 10),
                zorder=2,
                width=0.85)
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\totalubadges.png')
    report.add('graph', 'Total Unique Badges', '\\totalubadges.png')

    merged.sort_values(['badges in period'],
                       inplace=True,
                       ascending=True,
                       na_position='first')

    plt.tight_layout()
    merged.plot(x='user',
                y='badges in period',
                kind='barh',
                figsize=(8, 10),
                zorder=2,
                width=0.85)
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\periodbadges.png')
    report.add('graph', 'Total Badges in Period', '\\periodbadges.png')

    merged.sort_values(['first time badges in period'],
                       inplace=True,
                       ascending=True,
                       na_position='first')

    plt.tight_layout()
    merged.plot(x='user',
                y='first time badges in period',
                kind='barh',
                figsize=(8, 10),
                zorder=2,
                width=0.85)
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\firstbadges.png')
    report.add('graph', 'First Time Badges in Period', '\\firstbadges.png')

    merged.sort_values(['user'], inplace=True, ascending=True)

    report.add('table', 'Badge Report Data', merged)

    report.makeHTML('Badge Assignments')
Ejemplo n.º 4
0
def main(driver, startdate, enddate, statuslabel, report):
    contactstruct = PIEdataVARS.contacts
    locationstruct = PIEdataVARS.locations
    inventoryreportstruct = PIEdataVARS.invreports
    appointmentstruct = PIEdataVARS.appointments

    container = []

    container.append(contactstruct)
    container.append(locationstruct)
    container.append(inventoryreportstruct)
    container.append(appointmentstruct)

    for struct in container:
        struct.endDate = enddate
        struct.startDate = startdate

    statusUpdate(statuslabel, 'Loading contacts, please be patient')

    #CONTACTS
    contacturl = contactstruct.urlList()
    contactframe = PieHandler.goandget(driver, contacturl, contactstruct)
    testy = contactframe['locationName'].value_counts().reset_index()
    testy.rename(columns={
        'locationName': 'contacts',
        'index': 'locationName'
    },
                 inplace=True)
    testy['abb'] = testy['locationName'].apply(lambda x: functions.getAbb(x))
    testy = testy.groupby('abb')['contacts'].sum().reset_index()

    #LOCATIONS
    statusUpdate(statuslabel, 'Loading locations, please keep being patient')
    locationurl = locationstruct.urlList()
    locationframe = PieHandler.goandget(driver, locationurl, locationstruct)
    locationframe['staffed_hours'] = vectorize(functions.getSeconds)(
        locationframe['assumedDuration-difference'])
    locationframe['abb'] = locationframe['location-shortName'].apply(
        lambda x: functions.getAbb(x))
    locationframe = locationframe.groupby(
        'abb')['staffed_hours'].sum().reset_index()
    locationframe = locationframe[['abb', 'staffed_hours']]
    supaframe = merge(locationframe,
                      testy,
                      left_on='abb',
                      right_on='abb',
                      how='outer')
    supaframe['contacts_per_hour'] = supaframe['contacts'] / supaframe[
        'staffed_hours']
    statusUpdate(statuslabel,
                 'Loading inventory reports, thanks for sticking around')

    #INVENTORY REPORTS
    inventoryurl = inventoryreportstruct.urlList()
    invframe = PieHandler.goandgetinv(driver, inventoryurl,
                                      'Letter(8.5" x 11")')
    invuseframe = PieHandler.invcounttwo(invframe)

    #PUTTING THINGS TOGETHER
    invuseframe['abb'] = invuseframe['lab'].apply(
        lambda x: functions.getAbb(x))

    invuseframe = invuseframe.groupby('abb')['paper_used'].sum().reset_index()
    supadupaframe = merge(supaframe, invuseframe, on='abb', how='outer')
    supadupaframe = supadupaframe[[
        'abb', 'staffed_hours', 'contacts', 'contacts_per_hour', 'paper_used'
    ]]
    supadupaframe['overall_score'] = supadupaframe[
        'contacts_per_hour'] * supadupaframe['paper_used']
    supadupaframe.sort_values(by=['overall_score'],
                              ascending=False,
                              inplace=True)
    supadupaframe = supadupaframe.reset_index(drop=True)
    report.add('table', 'Lab Contacts/Hour and Paper Usage (Reams)',
               supadupaframe)

    #APPOINTMENTS
    statusUpdate(
        statuslabel,
        'Moving on to appointments now. This will be worth it I swear.')
    appointmenturl = appointmentstruct.urlList()
    appointmentframe = PieHandler.goandget(driver, appointmenturl,
                                           appointmentstruct)

    shiftlocationframe = appointmentframe['shiftType-name'].value_counts(
    ).to_frame()
    plt.tight_layout()
    shiftlocationframe.plot.pie(
        y='shiftType-name',
        autopct=functions.make_autopct(
            shiftlocationframe['shiftType-name'].tolist()),
        fontsize=15,
        figsize=(8, 8))
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\shiftlocations.png')
    report.add('graph', 'Appointment Assignments', '\\shiftlocations.png')

    buildingframe = appointmentframe[
        'ticket-residence-building-name'].value_counts().to_frame()
    plt.tight_layout()
    buildingframe.plot.bar(figsize=(8, 8))
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\appointmentlocals.png')
    report.add('graph', 'Appointment Locations', '\\appointmentlocals.png')

    appointmentframe['month'] = appointmentframe['scheduledStartTime'].apply(
        lambda x: functions.getMonth(x))
    smallboi = appointmentframe[['month', 'shiftType-shortName']]
    pivoto = smallboi.pivot_table(index='month',
                                  columns='shiftType-shortName',
                                  values='shiftType-shortName',
                                  aggfunc=len)

    statusUpdate(statuslabel, 'GeneratingReport')

    plt.tight_layout()
    pivoto.plot.bar()
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\timeandbuilding.png')
    report.add('graph', 'Appointment Months', '\\timeandbuilding.png')

    report.makeHTML('Lab Breakdown')
Ejemplo n.º 5
0
def main(driver, startdate, enddate, statuslabel, report):
    chats = PIEdataVARS.chat_messages
    chats.startDate = startdate
    chats.endDate = enddate
    urllist = chats.urlList()
    chatframe = PieHandler.goandget(driver, urllist, chats)

    chatframe = chatframe[['id', 'alert', 'created', 'text', 'user-username', 'user-firstName', 'user-lastName']]

    #find counts of messages sent
    message_counts = chatframe[['user-username', 'id']]
    message_counts = message_counts.groupby('user-username').count()

    def parseIcons(message):
        # first count number of colons in message
        iconsused = []
        count = message.count(':')
        if count < 2:
            return iconsused
        if (count % 2) == 0:
            # even number = good
            split = message.split(':')
            return split[1:]
        else:
            # odd number = bad
            split = message.split(':')
            return split[1:]

    chatframe['colons'] = chatframe['text'].map(lambda x: parseIcons(x))
    badlist = [' ', '  ', 'https']
    iconlist = chatframe['colons'].tolist()
    kingdict = {}
    for icons in iconlist:
        for icon in icons:
            icon = icon.strip()
            if len(icon) > 20 or len(icon) < 3:
                continue
            if icon in badlist:
                continue
            if not icon[0].isalpha():
                continue
            if icon in kingdict:
                kingdict[icon] = kingdict[icon] + 1
            else:
                kingdict[icon] = 1

    finaldict = {}
    for icon,count in kingdict.items():
        if count > 10:
            finaldict[icon] = count

    def iconlistcleaner(x):
        temper = []
        for icon in x:
            if icon in kingdict:
                temper.append(icon)
        return temper

    chatframe['icons'] = chatframe['colons'].map(lambda x: iconlistcleaner(x))
    chatframe = chatframe[['id', 'user-username', 'icons']]

    chatframe['num_icons'] = chatframe['icons'].map(lambda x: len(x))

    #total number of messages
    beefer = chatframe[['user-username', 'id']]
    totalunique = beefer.groupby(['user-username']).count()

    #total icons sent
    icoframe = chatframe[['user-username', 'num_icons']]
    totalicons = icoframe.groupby(['user-username']).sum()
    #totalunique.columns.names = ['user-username', 'total icons sent']

    #fold the frames down

    def find_max(x):
        if (len(x) == 0):
            return 'N/A'
        else:
            maxer = 0
            val = 'N/A'
            for key, value in x.items():
                if value > maxer:
                    val = key
                    maxer = value
            return val + ' (' + str(maxer) + ')'

    modded = chatframe[['user-username', 'icons']]
    merged = modded.groupby('user-username').agg({'icons': 'sum'})
    merged['counts'] = merged['icons'].apply(lambda x: dict(Counter(x)))
    merged['most_used (times)'] = merged['counts'].apply(lambda x: find_max(x))
    merged['unique icons used'] = merged['counts'].apply(lambda x: len(x))
    merged = merged[['most_used (times)', 'unique icons used']]

    usertable = merge(totalunique,totalicons, left_index=True, right_index=True)
    usertable = merge(usertable,merged, left_index=True,right_index=True)
    usertable['avg icons/message'] = usertable['num_icons'] / usertable['id']
    usertable=usertable.reset_index()
    usertable.columns = ['username', 'total messages sent', 'total icons sent', 'most used (times)', 'unique icons used', 'avg icons/message']

    smaller = usertable.sort_values(by=['total messages sent'], ascending=False).head(20)
    smaller = smaller.sort_values(by=['total messages sent'], ascending=True)
    smaller = smaller[['username', 'total messages sent', 'total icons sent']]

    plt.tight_layout()
    smaller.plot(x='username',kind='barh', figsize=(8, 10), zorder=2, width=0.85)
    plt.tight_layout()
    plt.savefig(htmlbase.figure_path + '\\totalmessages.png')

    report.add('table', 'User Icon Usage', usertable)
    report.add('graph', 'Total Messages sent', '\\totalmessages.png')

    # now do the exact same thing, but with icons. Will need to melt.
    #make new version of chatframe that only has what I care about
    iconframe = chatframe[['id', 'user-username', 'icons']]
    melted = iconframe.explode('icons')

    # find total messages appeared in
    iconappearance = melted.groupby(['id','icons']).count().groupby(['icons']).count()
    iconappearance.rename(columns={iconappearance.columns[0]: "messages appeared in"}, inplace=True)

    # find total uses
    uses = melted.groupby('icons').count()
    uses.rename(columns={uses.columns[1]: "times used"}, inplace = True)
    uses = uses[['times used']]

    # most used by
    usedby = melted.groupby(['icons','user-username'], as_index=False)['id'].count()
    inner = usedby.groupby(['icons']).agg({'id':'max'}).reset_index()
    usedby = merge(left = usedby, right=inner, how='inner', left_on=['icons','id'], right_on=['icons','id'])
    usedby = usedby.set_index('icons')

    usedby['most used by (times)'] = usedby['user-username'] + ' (' + usedby['id'].astype(str) + ')'
    usedby = usedby[['most used by (times)']]
    usedby = usedby.groupby(['icons']).agg({'most used by (times)':'first'})

    # unique users
    uniqueusers = melted.groupby(['icons','user-username'], as_index=False)['id'].count().groupby(['icons']).agg({'user-username':'******'})
    uniqueusers.rename(columns={uniqueusers.columns[0]: "unique users"}, inplace=True)

    # join em all into a biggy wiggy
    merged = merge(iconappearance,uses, left_index=True, right_index=True)
    merged = merge(merged,usedby,left_index=True,right_index=True)
    merged = merge(merged, uniqueusers, left_index=True, right_index=True).reset_index()
    merged.rename(columns={merged.columns[0]: "icon name"}, inplace=True)

    report.add('table', 'Icon User Usage', merged)


    report.makeHTML('Chat Icon Usage')