Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions api/object_specifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Software(BaseModel):
machine_id: int
schedule_mode: str
usage_scenario_variables: Optional[Dict[str, str]] = None
repo_to_watch_url: Optional[str] = None

model_config = ConfigDict(extra='forbid')

Expand Down
10 changes: 9 additions & 1 deletion api/scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ async def software_add(software: Software, user: User = Depends(authenticate)):

if software.usage_scenario_variables is None:
software.usage_scenario_variables = {}

if software.repo_to_watch_url is not None and software.repo_to_watch_url.strip() == '':
software.repo_to_watch_url = None

if not DB().fetch_one('SELECT id FROM machines WHERE id=%s AND available=TRUE', params=(software.machine_id,)):
raise RequestValidationError('Machine does not exist')
Expand All @@ -765,6 +768,11 @@ async def software_add(software: Software, user: User = Depends(authenticate)):
except ValueError as exc: # We accept the value error here if the repository is unknown, but log it for now
error_helpers.log_error('Repository could not be checked in /v1/software/add.', exception=exc)

if software.repo_to_watch_url:
try:
utils.check_repo(software.repo_to_watch_url, software.branch)
except ValueError as exc:
error_helpers.log_error('Watch repository could not be checked in /v1/software/add.', exception=exc)

if software.schedule_mode in ['daily', 'weekly', 'commit', 'commit-variance', 'tag', 'tag-variance']:

Expand All @@ -775,7 +783,7 @@ async def software_add(software: Software, user: User = Depends(authenticate)):
if 'commit' in software.schedule_mode:
last_marker = utils.get_repo_last_marker(software.repo_url, 'commits')

Watchlist.insert(name=software.name, image_url=software.image_url, repo_url=software.repo_url, branch=software.branch, filename=software.filename, machine_id=software.machine_id, usage_scenario_variables=software.usage_scenario_variables, user_id=user._id, schedule_mode=software.schedule_mode, last_marker=last_marker)
Watchlist.insert(name=software.name, image_url=software.image_url, repo_url=software.repo_url, repo_to_watch_url=software.repo_to_watch_url, branch=software.branch, filename=software.filename, machine_id=software.machine_id, usage_scenario_variables=software.usage_scenario_variables, user_id=user._id, schedule_mode=software.schedule_mode, last_marker=last_marker)

job_ids_inserted = []

Expand Down
26 changes: 18 additions & 8 deletions cron/watchlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
def schedule_watchlist_item():
query = """
SELECT
id, name, repo_url, branch, filename, usage_scenario_variables, machine_id, user_id, schedule_mode, last_marker,
id, name, repo_url, repo_to_watch_url, branch, filename, usage_scenario_variables, machine_id, user_id, schedule_mode, last_marker,
DATE(last_scheduled) >= DATE(NOW()) as "scheduled_today",
DATE(last_scheduled) >= DATE(NOW() - INTERVAL '7 DAYS') as "scheduled_last_week"
FROM watchlist
"""
data = DB().fetch_all(query)

for [item_id, name, repo_url, branch, filename, usage_scenario_variables, machine_id, user_id, schedule_mode, last_marker, scheduled_today, scheduled_last_week] in data:
for [item_id, name, repo_url, repo_to_watch_url, branch, filename, usage_scenario_variables, machine_id, user_id, schedule_mode, last_marker, scheduled_today, scheduled_last_week] in data:
print(f"Watchlist item is on {schedule_mode} schedule", repo_url, branch, filename, machine_id)

if schedule_mode == 'one-off':
Expand All @@ -50,26 +50,36 @@ def schedule_watchlist_item():
Job.insert('run', user_id=user_id, name=name, url=repo_url, email=None, branch=branch, filename=filename, usage_scenario_variables=usage_scenario_variables, machine_id=machine_id)
print('\tInserted')
elif schedule_mode in ['tag', 'tag-variance']:
last_marker_new = utils.get_repo_last_marker(repo_url, 'tags')
if repo_to_watch_url:
last_marker_new = utils.get_repo_last_marker(repo_to_watch_url, 'tags')
else:
last_marker_new = utils.get_repo_last_marker(repo_url, 'tags')

print('Last marker is', last_marker, ' - Current maker is', last_marker_new)
if last_marker == last_marker_new:
continue
amount = 3 if 'variance' in schedule_mode else 1
for _ in range(0,amount):
Job.insert('run', user_id=user_id, name=name, url=repo_url, email=None, branch=branch, filename=filename, usage_scenario_variables=usage_scenario_variables, machine_id=machine_id)
print('Updating Hash', last_marker_new)
DB().query('UPDATE watchlist SET last_marker = %s WHERE id = %s', params=(last_marker_new, item_id, ))

print('Updating Hash', last_marker_new)
DB().query('UPDATE watchlist SET last_marker = %s WHERE id = %s', params=(last_marker_new, item_id, ))

elif schedule_mode in ['commit', 'commit-variance']:
last_marker_new = utils.get_repo_last_marker(repo_url, 'commits')
if repo_to_watch_url:
last_marker_new = utils.get_repo_last_marker(repo_to_watch_url, 'commits')
else:
last_marker_new = utils.get_repo_last_marker(repo_url, 'commits')

print('Last marker is', last_marker, ' - Current maker is', last_marker_new)
if last_marker == last_marker_new:
continue
amount = 3 if 'variance' in schedule_mode else 1
for _ in range(0,amount):
print('Updating Hash', last_marker_new)
Job.insert('run', user_id=user_id, name=name, url=repo_url, email=None, branch=branch, filename=filename, usage_scenario_variables=usage_scenario_variables, machine_id=machine_id)
DB().query('UPDATE watchlist SET last_marker = %s WHERE id = %s', params=(last_marker_new, item_id, ))

print('Updating Hash', last_marker_new)
DB().query('UPDATE watchlist SET last_marker = %s WHERE id = %s', params=(last_marker_new, item_id, ))

if __name__ == '__main__':
try:
Expand Down
1 change: 1 addition & 0 deletions docker/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ CREATE TABLE watchlist (
name text,
image_url text,
repo_url text,
repo_to_watch_url text,
categories integer[],
branch text NOT NULL,
filename text NOT NULL,
Expand Down
23 changes: 23 additions & 0 deletions frontend/js/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const populateFieldsFromURL = () => {
if (urlParams.has('repo_url')) { // precedence
document.querySelector('input[name="repo_url"]').value = escapeString(urlParams.get('repo_url'));
}
if (urlParams.has('repo_to_watch_url')) {
document.querySelector('input[name="repo_to_watch_url"]').value = escapeString(urlParams.get('repo_to_watch_url'));
}
if (urlParams.has('filename')) {
document.querySelector('input[name="filename"]').value = escapeString(urlParams.get('filename'));
}
Expand Down Expand Up @@ -118,6 +121,26 @@ const updateRemoveButtonsVisibility = () => {
});


$('#variables-container').on('click', '.remove-variable', function (e) {
$(this).closest('.variable-row').remove();
updateRemoveButtonsVisibility();
});

const toggleWatchRepoVisibility = () => {
const scheduleModeSelect = document.getElementById('schedule-mode-select');
const watchRepoDiv = document.getElementById('watch-different-repo');
const commitModes = ['commit', 'commit-variance', 'tag', 'tag-variance'];

if (commitModes.includes(scheduleModeSelect.value)) {
watchRepoDiv.classList.remove('hidden');
} else {
watchRepoDiv.classList.add('hidden');
}
};

toggleWatchRepoVisibility();
$('#schedule-mode-select').on('change', toggleWatchRepoVisibility);

document.forms[0].onsubmit = async (event) => {
event.preventDefault();

Expand Down
13 changes: 11 additions & 2 deletions frontend/request.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h1 class="ui header float left">
</div>
<p style="text-align: right;">Find the specifications of the machines <a href="https://docs.green-coding.io/docs/measuring/measurement-cluster/">in our documentation</a></p>
<div class="ui fluid icon input">
<select name="schedule_mode" class="ui fluid dropdown" required>
<select name="schedule_mode" id="schedule-mode-select" class="ui fluid dropdown" required>
<option value=''>-- Select measurement interval --</option>
<option value='one-off'>One-Off [Free - Fair use]</option>
<option value='variance'>Variance test (3 measurements in a row) [Premium]</option>
Expand All @@ -118,6 +118,12 @@ <h1 class="ui header float left">
<option value='statistical-significance'>Do 10 runs to evaluate statistical significance [Premium]</option>
</select>
</div>
<div id="watch-different-repo" class="hidden">
<p style="text-align: right;">You can watch a different repo for changes and then benchmark the repository specified above.</p>
<div class="ui fluid icon input">
<input type="text" placeholder="Repo to watch (optional - defaults to the repo above)" name="repo_to_watch_url">
</div>
</div>
<p style="text-align: right;">Define variables to be used. See the documentation <a href="https://docs.green-coding.io/docs/measuring/usage-scenario/#variables" target="_blank">here</a>.</p>
<div id="variables-container">
</div>
Expand All @@ -127,7 +133,10 @@ <h1 class="ui header float left">
</button>
</div>
</div>
<button class="positive ui button" style="margin-top: 20px;">Submit software</button>

<button class="positive ui button" style="margin-top: 20px;">Submit software</button>

</div>
</form>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions lib/watchlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
class Watchlist():
#pylint:disable=redefined-outer-name
@classmethod
def insert(cls, *, name, image_url, repo_url, branch, filename, usage_scenario_variables, machine_id, user_id, schedule_mode, last_marker):
def insert(cls, *, name, image_url, repo_url, repo_to_watch_url, branch, filename, usage_scenario_variables, machine_id, user_id, schedule_mode, last_marker):
# Watchlist items never insert / use emails as they are always premium and made by admin
# So they need no notification on success / add
insert_query = """
INSERT INTO
watchlist (name, image_url, repo_url, branch, filename, usage_scenario_variables, machine_id, last_marker, user_id, schedule_mode, created_at)
watchlist (name, image_url, repo_url, repo_to_watch_url, branch, filename, usage_scenario_variables, machine_id, last_marker, user_id, schedule_mode, created_at)
VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW()) RETURNING id;
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW()) RETURNING id;
"""
params = (name, image_url, repo_url, branch, filename, json.dumps(usage_scenario_variables), machine_id, last_marker, user_id, schedule_mode,)
params = (name, image_url, repo_url, repo_to_watch_url, branch, filename, json.dumps(usage_scenario_variables), machine_id, last_marker, user_id, schedule_mode,)
return DB().fetch_one(insert_query, params=params)[0]
Loading