Skip to content
Snippets Groups Projects
Commit 48939e84 authored by lche0021's avatar lche0021
Browse files

added avg_install.py to get the average num of software install per week in past 12 week

parent bc87f2ca
No related branches found
No related tags found
2 merge requests!464Fix listdeps,!442Smoke test
#!/usr/bin/env python3
# run module load python/3.8.5-gcc8-static first
from pathlib import Path
import os
import pandas as pd
import time
import datetime
import collections
import numpy as np
nweek = 12
modulepath = Path('/usr/local/Modules/modulefiles')
softwares = list(modulepath.glob('*/'))
modulefiles = [list(i.glob('**/[!.]*')) for i in softwares if i.is_dir() and os.access(i, os.R_OK)]
lastm = {datetime.datetime.fromtimestamp(j.stat().st_mtime): j for i in modulefiles for j in i}
today = datetime.date.today()
week = datetime.timedelta(weeks=1)
interval = np.array([today - week*i for i in range(nweek+1)][::-1])
def quantize_week(date):
week = interval[:-1][(interval[:-1] <= date) & (date < interval[1:])]
return week.item()
byweek = collections.defaultdict(list)
for k, v in lastm.items():
mod_day = datetime.date(*k.timetuple()[:3])
if mod_day >= interval[0]:
byweek[quantize_week(mod_day)].append(v)
avg_install = np.mean([len(i) for i in byweek.values()])
print(avg_install)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment