Skip to content

Commit eb404e7

Browse files
SBOne-KenobiRustam Sadykov
authored andcommitted
add script to build aggregated data
1 parent ecbb98d commit eb404e7

File tree

2 files changed

+132
-25
lines changed

2 files changed

+132
-25
lines changed

.github/workflows/night-statistics-monitoring.yml

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,33 @@ on:
55
- cron: '0 0 * * *'
66

77
env:
8+
data_branch: monitoring-data
9+
data_path: monitoring/data
10+
aggregated_data_branch: monitoring-aggregated-data
11+
aggregated_data_path: monitoring/aggregated_data
812
monitoring_properties: monitoring/monitoring.properties
913
output_stats: stats.json
10-
history_file: monitoring/history.json
11-
coverage_graph_file: monitoring/coverage_graph.png
12-
quantitative_graph_file: monitoring/quantitative_graph.png
1314
KOTLIN_HOME: /usr
1415

1516
jobs:
1617
build_and_run_monitoring:
1718
runs-on: ubuntu-20.04
1819
steps:
19-
- name: Checkout repository
20+
- name: Checkout main
2021
uses: actions/checkout@v3
2122

23+
- name: Checkout monitoring data
24+
uses: actions/checkout@v3
25+
with:
26+
ref: ${{ env.data_branch }}
27+
path: ${{ env.data_path }}
28+
29+
- name: Checkout aggregated monitoring data
30+
uses: actions/checkout@v3
31+
with:
32+
ref: ${{ env.aggregated_data_branch }}
33+
path: ${{ env.aggregated_data_path }}
34+
2235
- uses: actions/setup-java@v3
2336
with:
2437
java-version: '8'
@@ -30,9 +43,6 @@ jobs:
3043
- uses: actions/setup-python@v4
3144
with:
3245
python-version: '3.9'
33-
cache: 'pip'
34-
- name: Install matplotlib
35-
run: pip install matplotlib
3646

3747
- name: Build and run monitoring UTBot Java
3848
run: |
@@ -42,23 +52,56 @@ jobs:
4252
utbot-junit-contest/build/libs/monitoring.jar \
4353
$output_stats
4454
45-
- name: Update history and render graphs
46-
run: |
47-
python monitoring/draw_stats_graphs.py \
48-
$history_file \
49-
$output_stats \
50-
$coverage_graph_file \
51-
$quantitative_graph_file
52-
5355
- name: Get current date
5456
id: date
55-
run: echo "::set-output name=date::$(date +'%d-%m-%Y')"
57+
run: |
58+
echo "::set-output name=date::$(date +'%Y-%m-%d')"
59+
echo "::set-output name=timestamp::$(date +%s)"
60+
echo "::set-output name=last_month::$(date --date='last month' +%s)"
5661
57-
- name: Commit and push graphs and statistics
62+
- name: Get commit hash
63+
id: metadata
64+
run: |
65+
echo "::set-output name=commit::$(git rev-parse HEAD)"
66+
echo "::set-output name=branch::$(git name-rev --name-only HEAD)"
67+
echo "::set-output name=build::$(date +'%Y.%-m')"
68+
69+
- name: Insert metadata
70+
run: |
71+
python monitoring/insert_metadata.py \
72+
$output_stats "$data_path/data-$branch-$date-$timestamp-$commit.json" \
73+
"$commit" "$build"
74+
env:
75+
date: ${{ steps.date.outputs.date }}
76+
timestamp: ${{ steps.date.outputs.timestamp }}
77+
commit: ${{ steps.metadata.outputs.commit }}
78+
branch: ${{ steps.metadata.outputs.branch }}
79+
build: ${{ steps.metadata.outputs.build }}
80+
81+
- name: Build aggregated data (last month)
82+
run: |
83+
python monitoring/build_aggregated_data.py \
84+
$data_path $aggregated_data_path/aggregated-data-$date.json \
85+
$timestamp_from $timestamp
86+
env:
87+
date: ${{ steps.date.outputs.date }}
88+
timestamp: ${{ steps.date.outputs.timestamp }}
89+
timestamp_from: ${{ steps.date.outputs.last_month }}
90+
91+
- name: Commit and push statistics
5892
uses: actions-js/push@master
5993
with:
94+
branch: ${{ env.data_branch }}
6095
message: 'night-monitoring-${{ steps.date.outputs.date }}'
61-
directory: './monitoring'
96+
directory: ${{ env.data_path }}
97+
github_token: ${{ secrets.GITHUB_TOKEN }}
98+
99+
- name: Commit and push aggregated statistics
100+
uses: actions-js/push@master
101+
with:
102+
branch: ${{ env.aggregated_data_branch }}
103+
message: 'night-monitoring-${{ steps.date.outputs.date }}'
104+
directory: ${{ env.aggregated_data_path }}
62105
github_token: ${{ secrets.GITHUB_TOKEN }}
63106

64107
- name: Upload logs
@@ -67,10 +110,3 @@ jobs:
67110
with:
68111
name: logs
69112
path: logs/utbot.log
70-
71-
- name: Upload statistics
72-
if: ${{ success() }}
73-
uses: actions/upload-artifact@v3
74-
with:
75-
name: statistics
76-
path: ${{ env.output_stats }}

monitoring/build_aggregated_data.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import json
2+
import re
3+
from os import listdir
4+
from os.path import isfile, join
5+
from sys import argv
6+
7+
"""
8+
Input files data requires names format *-<timestamp>-<commit>.json
9+
"""
10+
FILE_FORMAT_REGEXP = re.compile(r'.+-(\d+)-[^-]+\.json')
11+
12+
13+
def get_file_timestamp(filename):
14+
result = FILE_FORMAT_REGEXP.fullmatch(filename)
15+
if result is None:
16+
return None
17+
return int(result.group(1))
18+
19+
20+
def check_timestamp(timestamp, timestamp_from, timestamp_to):
21+
return timestamp is not None and timestamp_from <= timestamp <= timestamp_to
22+
23+
24+
def get_file_seq(input_data_dir, timestamp_from, timestamp_to):
25+
for filename in listdir(input_data_dir):
26+
path = join(input_data_dir, filename)
27+
if isfile(path):
28+
timestamp = get_file_timestamp(filename)
29+
if check_timestamp(timestamp, timestamp_from, timestamp_to):
30+
yield path, timestamp
31+
32+
33+
def get_stats_seq(input_data_dir, timestamp_from, timestamp_to):
34+
for file, timestamp in get_file_seq(input_data_dir, timestamp_from, timestamp_to):
35+
with open(file, "r") as f:
36+
stats = json.load(f)
37+
yield stats, timestamp
38+
39+
40+
def transform_stats(stats, timestamp):
41+
del stats['metadata']
42+
stats['timestamp'] = timestamp
43+
return stats
44+
45+
46+
def aggregate_stats(stats_seq):
47+
result = []
48+
for stats, timestamp in stats_seq:
49+
result.append(transform_stats(stats, timestamp))
50+
return result
51+
52+
53+
def main():
54+
args = argv[1:]
55+
if len(args) != 4:
56+
raise RuntimeError(
57+
f"Expected <input data dir> <output file> "
58+
f"<timestamp from> <timestamp to> "
59+
f"but got {' '.join(args)}"
60+
)
61+
(input_data_dir, output_file, timestamp_from, timestamp_to) = args
62+
timestamp_from = int(timestamp_from)
63+
timestamp_to = int(timestamp_to)
64+
stats_seq = get_stats_seq(input_data_dir, timestamp_from, timestamp_to)
65+
result = aggregate_stats(stats_seq)
66+
with open(output_file, "w") as f:
67+
json.dump(result, f, indent=4)
68+
69+
70+
if __name__ == '__main__':
71+
main()

0 commit comments

Comments
 (0)