Spaces:
Sleeping
Sleeping
Commit ·
fcaa886
1
Parent(s): 35f1278
cw2.py
CHANGED
|
@@ -44,6 +44,8 @@ def get_views_by_continent(data, doc_uuid):
|
|
| 44 |
def get_visitor_useragents(data):
|
| 45 |
fig = plt.figure(figsize=(10, 6))
|
| 46 |
data['visitor_useragent'].value_counts().plot(kind='bar')
|
|
|
|
|
|
|
| 47 |
return fig
|
| 48 |
|
| 49 |
|
|
@@ -51,6 +53,8 @@ def get_visitor_browsers(data):
|
|
| 51 |
fig = plt.figure(figsize=(10, 6))
|
| 52 |
data['visitor_browser'] = data['visitor_useragent'].str.split('/').str[0]
|
| 53 |
data['visitor_browser'].value_counts().plot(kind='bar')
|
|
|
|
|
|
|
| 54 |
return fig
|
| 55 |
|
| 56 |
|
|
@@ -60,33 +64,14 @@ def get_avid_readers(data):
|
|
| 60 |
|
| 61 |
def plot_avid_readers(data):
|
| 62 |
fig = plt.figure(figsize=(11, 7))
|
|
|
|
| 63 |
get_avid_readers(data).sort_values(ascending=True).plot(kind='barh')
|
|
|
|
|
|
|
|
|
|
| 64 |
return fig
|
| 65 |
|
| 66 |
|
| 67 |
-
# def get_doc_visitors(doc_uuid):
|
| 68 |
-
# return data_tiny[data_tiny['subject_doc_id'] == doc_uuid]['visitor_uuid'].unique()
|
| 69 |
-
#
|
| 70 |
-
#
|
| 71 |
-
# def get_visitor_docs(visitor_uuid):
|
| 72 |
-
# return data_tiny[data_tiny['visitor_uuid'] == visitor_uuid]['subject_doc_id'].dropna().unique()
|
| 73 |
-
#
|
| 74 |
-
#
|
| 75 |
-
# def get_also_likes_doc(doc_uuid, visitor_uuid, ascending):
|
| 76 |
-
# visitor_uuids = get_doc_visitors(doc_uuid)
|
| 77 |
-
# doc_uuids = sum([list(get_visitor_docs(reader)) for reader in visitor_uuids], [])
|
| 78 |
-
# return pd.Series(doc_uuids).value_counts(ascending=ascending)
|
| 79 |
-
#
|
| 80 |
-
#
|
| 81 |
-
# def also_like(doc_uuid, visitor_uuid, ascending):
|
| 82 |
-
# visitor_uuids = get_doc_visitors(doc_uuid)
|
| 83 |
-
# y = []
|
| 84 |
-
# for reader in visitor_uuids:
|
| 85 |
-
# for doc in get_visitor_docs(reader):
|
| 86 |
-
# if doc != doc_uuid and doc not in get_visitor_docs(visitor_uuid).tolist():
|
| 87 |
-
# y.append([reader, doc])
|
| 88 |
-
# return pd.DataFrame(y)
|
| 89 |
-
|
| 90 |
# Req 5a
|
| 91 |
def get_doc_visitors(data, doc_uuid):
|
| 92 |
readers = data[data['env_type'] == "reader"]
|
|
@@ -140,7 +125,7 @@ def also_like_graph(data, doc_uuid, visitor_uuid, ascending):
|
|
| 140 |
dot.edge(str(row[0]), str(row[1]))
|
| 141 |
|
| 142 |
# print(dot.source)
|
| 143 |
-
|
| 144 |
dot.render('output.dot').replace('\\', '/')
|
| 145 |
|
| 146 |
(graph,) = pydot.graph_from_dot_file('output.dot')
|
|
|
|
| 44 |
def get_visitor_useragents(data):
|
| 45 |
fig = plt.figure(figsize=(10, 6))
|
| 46 |
data['visitor_useragent'].value_counts().plot(kind='bar')
|
| 47 |
+
plt.xlabel("Visitor User Agents")
|
| 48 |
+
plt.ylabel("Frequency")
|
| 49 |
return fig
|
| 50 |
|
| 51 |
|
|
|
|
| 53 |
fig = plt.figure(figsize=(10, 6))
|
| 54 |
data['visitor_browser'] = data['visitor_useragent'].str.split('/').str[0]
|
| 55 |
data['visitor_browser'].value_counts().plot(kind='bar')
|
| 56 |
+
plt.xlabel("Visitor Browsers")
|
| 57 |
+
plt.ylabel("Frequency")
|
| 58 |
return fig
|
| 59 |
|
| 60 |
|
|
|
|
| 64 |
|
| 65 |
def plot_avid_readers(data):
|
| 66 |
fig = plt.figure(figsize=(11, 7))
|
| 67 |
+
plt.tight_layout()
|
| 68 |
get_avid_readers(data).sort_values(ascending=True).plot(kind='barh')
|
| 69 |
+
plt.xlabel("Time in minutes")
|
| 70 |
+
plt.ylabel("Visitor UUID")
|
| 71 |
+
plt.tight_layout()
|
| 72 |
return fig
|
| 73 |
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Req 5a
|
| 76 |
def get_doc_visitors(data, doc_uuid):
|
| 77 |
readers = data[data['env_type'] == "reader"]
|
|
|
|
| 125 |
dot.edge(str(row[0]), str(row[1]))
|
| 126 |
|
| 127 |
# print(dot.source)
|
| 128 |
+
|
| 129 |
dot.render('output.dot').replace('\\', '/')
|
| 130 |
|
| 131 |
(graph,) = pydot.graph_from_dot_file('output.dot')
|