Skip to content

Commit a3ca55b

Browse files
committed
change database structure (tmp)
1 parent 8ca42c1 commit a3ca55b

File tree

3 files changed

+124
-164
lines changed

3 files changed

+124
-164
lines changed

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

Lines changed: 49 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,44 @@ 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+
61+
- name: Get commit hash
62+
id: metadata
63+
run: |
64+
echo "::set-output name=commit::$(git rev-parse HEAD)"
65+
echo "::set-output name=branch::$(git name-rev --name-only HEAD)"
5666
57-
- name: Commit and push graphs and statistics
67+
- name: Insert metadata
68+
run: |
69+
python monitoring/insert_metadata.py \
70+
$output_stats "$data_path/data-$branch-$date-$timestamp-$commit.json" \
71+
$commit "$build"
72+
env:
73+
date: ${{ steps.date.outputs.date }}
74+
timestamp: ${{ steps.date.outputs.timestamp }}
75+
commit: ${{ steps.metadata.outputs.commit }}
76+
branch: ${{ steps.metadata.outputs.branch }}
77+
build: 0
78+
79+
- name: Commit and push statistics
80+
uses: actions-js/push@master
81+
with:
82+
branch: ${{ env.data_branch }}
83+
message: 'night-monitoring-${{ steps.date.outputs.date }}'
84+
directory: ${{ env.data_path }}
85+
github_token: ${{ secrets.GITHUB_TOKEN }}
86+
87+
- name: Commit and push aggregated statistics
5888
uses: actions-js/push@master
5989
with:
90+
branch: ${{ env.aggregated_data_branch }}
6091
message: 'night-monitoring-${{ steps.date.outputs.date }}'
61-
directory: './monitoring'
92+
directory: ${{ env.aggregated_data_path }}
6293
github_token: ${{ secrets.GITHUB_TOKEN }}
6394

6495
- name: Upload logs
@@ -67,10 +98,3 @@ jobs:
6798
with:
6899
name: logs
69100
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/draw_stats_graphs.py

Lines changed: 0 additions & 139 deletions
This file was deleted.

monitoring/insert_metadata.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import json
2+
from collections import defaultdict
3+
from os.path import exists
4+
from sys import argv
5+
6+
7+
def load(json_file):
8+
if exists(json_file):
9+
with open(json_file, "r") as f:
10+
return json.load(f)
11+
return None
12+
13+
14+
def transform_stats(stats):
15+
common_prefix = "covered_instructions_count"
16+
denum = stats["total_instructions_count"]
17+
18+
nums_keys = [(key, key.removeprefix(common_prefix)) for key in stats.keys() if key.startswith(common_prefix)]
19+
20+
for (key, by) in nums_keys:
21+
num = stats[key]
22+
stats["total_coverage" + by] = 100 * num / denum if denum != 0 else 0
23+
del stats[key]
24+
25+
del stats["total_instructions_count"]
26+
27+
return stats
28+
29+
30+
def transform_and_combine_stats(stats_list):
31+
new_stats = defaultdict(lambda: 0.0)
32+
33+
# calculate average by all keys
34+
for n, stats in enumerate(stats_list, start=1):
35+
transformed = transform_stats(stats)
36+
for key in transformed:
37+
new_stats[key] = new_stats[key] + (transformed[key] - new_stats[key]) / n
38+
39+
return new_stats
40+
41+
42+
def insert_metadata(stats, commit, build):
43+
stats['commit_hash'] = commit
44+
stats['build_number'] = build
45+
46+
# TODO: insert environment information
47+
48+
return stats
49+
50+
51+
def transform_and_insert_metadata(stats_file, commit, build):
52+
stats = load(stats_file)
53+
if stats is None:
54+
raise FileNotFoundError("File with stats does not exist!")
55+
stats = transform_and_combine_stats(stats)
56+
stats = insert_metadata(stats, commit, build)
57+
return stats
58+
59+
60+
def main():
61+
args = argv[1:]
62+
if len(args) != 4:
63+
raise RuntimeError(
64+
f"Expected <stats file> <output file> "
65+
f"<commit hash> <build number> "
66+
f"but got {' '.join(args)}"
67+
)
68+
(stats_file, output_file, commit, build) = args
69+
stats = transform_and_insert_metadata(stats_file, commit, build)
70+
with open(output_file, "w") as f:
71+
json.dump(stats, f, indent=4)
72+
73+
74+
if __name__ == "__main__":
75+
main()

0 commit comments

Comments
 (0)