def _load_graph(self, info_cache): rpc = self.parent.rpc cid = self.config['campaign_id'] visits = info_cache['visits'] operating_systems = {} unknown_os = 'Unknown OS' for visit in visits: user_agent = ua_parser.parse_user_agent(visit['visitor_details']) if user_agent: operating_systems[user_agent.os_name] = operating_systems.get(user_agent.os_name, 0) + 1 else: operating_systems[unknown_os] = operating_systems.get(unknown_os, 0) + 1 os_names = operating_systems.keys() os_names.sort(key=lambda name: operating_systems[name]) os_names.reverse() bars = [] for os_name in os_names: bars.append(operating_systems[os_name]) width = 0.25 ax = self.axes[0] bars = ax.bar(range(len(bars)), bars, width) ax.set_ylabel('Total Visits') ax.set_title('Visitor OS Information') ax.set_xticks(map(lambda x: float(x) + (width / 2), range(len(bars)))) ax.set_xticklabels(os_names, rotation=30) for col in bars: height = col.get_height() ax.text(col.get_x() + col.get_width() / 2.0, height, str(height), ha='center', va='bottom') self.figure.subplots_adjust(bottom=0.25) return info_cache
def _load_graph(self, info_cache): visits = info_cache['visits'] operating_systems = collections.Counter() for visit in visits: ua = ua_parser.parse_user_agent(visit.visitor_details) operating_systems.update([ua.os_name or 'Unknown OS' if ua else 'Unknown OS']) os_names = sorted(operating_systems.keys()) bars = [operating_systems[os_name] for os_name in os_names] self.graph_bar(bars, len(OSFamily), os_names) return
def _load_graph(self, info_cache): visits = info_cache['visits']['edges'] if not len(visits): self._graph_null_pie('No Visitor Information') return operating_systems = collections.Counter() for visit in visits: ua = ua_parser.parse_user_agent(visit['node']['userAgent']) operating_systems.update([ua.os_name or 'Unknown OS' if ua else 'Unknown OS']) (os_names, count) = tuple(zip(*reversed(sorted(operating_systems.items(), key=lambda item: item[1])))) self.graph_pie(count, labels=tuple("{0:,}".format(os) for os in count), legend_labels=os_names) return
def _load_graph(self, info_cache): visits = info_cache['visits'] if not len(visits): self._graph_null_pie('No Visitor Information') return operating_systems = collections.Counter() for visit in visits: ua = ua_parser.parse_user_agent(visit.visitor_details) operating_systems.update([ua.os_name or 'Unknown OS' if ua else 'Unknown OS']) (os_names, count) = tuple(zip(*reversed(sorted(operating_systems.items(), key=lambda item: item[1])))) self.graph_pie(count, labels=tuple("{0:,}".format(os) for os in count), legend_labels=os_names) return
def _load_graph(self, info_cache): visits = info_cache['visits']['edges'] if not len(visits): self._graph_null_bar('No Visitor Information') return operating_systems = collections.Counter() for visit in visits: user_agent = None if visit['node']['userAgent']: user_agent = ua_parser.parse_user_agent(visit['node']['userAgent']) operating_systems.update([user_agent.os_name if user_agent and user_agent.os_name else 'Unknown OS']) os_names = sorted(operating_systems.keys()) bars = [operating_systems[os_name] for os_name in os_names] self.graph_bar(bars, os_names) return
def _load_graph(self, info_cache): visits = info_cache['visits'] operating_systems = collections.Counter() for visit in visits: ua = ua_parser.parse_user_agent(visit.visitor_details) operating_systems.update([ua.os_name or 'Unknown OS' if ua else 'Unknown OS']) os_names = list(operating_systems.keys()) os_names.sort(key=lambda name: operating_systems[name]) os_names.reverse() bars = [] for os_name in os_names: bars.append(operating_systems[os_name]) self.graph_bar(bars, color=[MPL_OS_COLORS[osn] for osn in os_names], xticklabels=os_names, ylabel='Total Visits') return
def _load_graph(self, info_cache): visits = info_cache['visits'] if not len(visits): self._graph_null_pie('No Visitor Information') return operating_systems = collections.Counter() for visit in visits: ua = ua_parser.parse_user_agent(visit.visitor_details) operating_systems.update([ua.os_name or 'Unknown OS' if ua else 'Unknown OS']) (os_names, count) = zip(*operating_systems.items()) colors = [MPL_OS_COLORS[osn] for osn in os_names] ax = self.axes[0] ax.pie(count, labels=os_names, labeldistance=1.05, colors=colors, autopct='%1.1f%%', shadow=True, startangle=45) ax.axis('equal') return
def _load_graph(self, info_cache): visits = info_cache['visits']['edges'] operating_systems = collections.Counter() for visit in visits: user_agent = None if visit['node']['visitorDetails']: user_agent = ua_parser.parse_user_agent( visit['node']['visitorDetails']) operating_systems.update([ user_agent.os_name if user_agent and user_agent.os_name else 'Unknown OS' ]) os_names = sorted(operating_systems.keys()) bars = [operating_systems[os_name] for os_name in os_names] self.graph_bar(bars, len(OSFamily), os_names) return
def _load_graph(self, info_cache): visits = info_cache['visits']['edges'] if not len(visits): self._graph_null_bar('No Visitor Information') return operating_systems = collections.Counter() for visit in visits: user_agent = None if visit['node']['userAgent']: user_agent = ua_parser.parse_user_agent( visit['node']['userAgent']) operating_systems.update([ user_agent.os_name if user_agent and user_agent.os_name else 'Unknown OS' ]) os_names = sorted(operating_systems.keys()) bars = [operating_systems[os_name] for os_name in os_names] self.graph_bar(bars, os_names) return
def _load_graph(self, info_cache): visits = info_cache['visits'] operating_systems = {} unknown_os = 'Unknown OS' for visit in visits: user_agent = ua_parser.parse_user_agent(visit['visitor_details']) if user_agent: operating_systems[user_agent.os_name] = operating_systems.get( user_agent.os_name, 0) + 1 else: operating_systems[unknown_os] = operating_systems.get( unknown_os, 0) + 1 os_names = operating_systems.keys() os_names.sort(key=lambda name: operating_systems[name]) os_names.reverse() bars = [] for os_name in os_names: bars.append(operating_systems[os_name]) width = 0.25 ax = self.axes[0] bars = ax.bar(range(len(bars)), bars, width) ax.set_ylabel('Total Visits') ax.set_title('Visitor OS Information') ax.set_yticks((1, )) ax.set_xticks(map(lambda x: float(x) + (width / 2), range(len(bars)))) ax.set_xticklabels(os_names, rotation=30) for col in bars: height = col.get_height() ax.text(col.get_x() + col.get_width() / 2.0, height, str(height), ha='center', va='bottom') self.figure.subplots_adjust(bottom=0.25) return info_cache