Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unique field to text data #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions fetch_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Created: 4 June,2020, 8:02 PM
# Email: aqeel.anwar@gatech.edu

import json
from pprint import pprint

from github import Github
import datetime
import csv
Expand Down Expand Up @@ -78,13 +81,15 @@
date_array = []
clone_array = {}
traffic_array = {}
unique_array = {}

# Generate array of dates under consideration
for d in range(14):
latest_date = str(earliest_date + datetime.timedelta(days=d))
# Assign zeros to clone and views statistics
clone_array[latest_date] = 0
traffic_array[latest_date] = 0
unique_array[latest_date] = 0

# Populate the clone statistics for the available date.
# For unavailable dates, the stat is already initialized to zero
Expand All @@ -94,6 +99,9 @@
for v in traffic_stat:
traffic_array[str(v.timestamp.date())] = v.count

for v in traffic_stat:
unique_array[str(v.timestamp.date())] = v.uniques

# Create the folder of username if it doesn't exists
path_to_folder = "repo_stats/" + args.username
if not os.path.exists(path_to_folder):
Expand All @@ -110,12 +118,15 @@
csv_file = open(csv_str, "w")
writer = csv.writer(csv_file)
# Define header of the CSV file
writer.writerow(["Date", "Clones", "Traffic"])
writer.writerow(["Date", "Clones", "Traffic", "Unique"])

clone_array = OrderedDict(sorted(clone_array.items(), key=lambda t: t[0]))
traffic_array = OrderedDict(
sorted(traffic_array.items(), key=lambda t: t[0])
)
unique_array = OrderedDict(
sorted(unique_array.items(), key=lambda t: t[0])
)

if os.path.exists(csv_str_temp):
# copyfile(csv_str, csv_str_temp)
Expand All @@ -133,15 +144,15 @@
).date()

if datetime_obj < compare_date:
writer.writerow([row[0], row[1], row[2]])
writer.writerow([row[0], row[1], row[2], row[3]])
else:
break
line_count += 1

for (key_clone, value_clone), (key_traffic, value_traffic) in zip(
clone_array.items(), traffic_array.items()
for (key_clone, value_clone), (key_traffic, value_traffic), (key_uinique, value_unique)in zip(
clone_array.items(), traffic_array.items(), unique_array.items()
):
writer.writerow([key_clone, value_clone, value_traffic])
writer.writerow([key_clone, value_clone, value_traffic, value_unique])

csv_file.close()

Expand All @@ -151,10 +162,8 @@
with open(csv_str) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
for row in csv_reader:
writer.writerow([row[0], row[1], row[2]])
writer.writerow([row[0], row[1], row[2], row[3]])
csv_file.close()

# Remove temp file.
os.remove(csv_str_temp)