Skip to content

Commit

Permalink
Merge pull request #94 from cs50/develop
Browse files Browse the repository at this point in the history
fix distro files showing up in results (v1.2.3)
  • Loading branch information
cmlsharp authored Mar 13, 2021
2 parents fb22414 + 109ae83 commit 912511d
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 254 deletions.
15 changes: 15 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
build:
image: latest

python:
version: 3.7
install:
- method: pip
path: .
extra_requirements:
- develop

sphinx:
builder: dirhtml

version: 2
5 changes: 5 additions & 0 deletions compare50/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ def main():
# Cross compare and rank all submissions, keep only top `n`
scores = _api.rank(subs, archive_subs, ignored_files, passes[0], n=args.n)

# If ranking produced no scores, there are no matches, stop
if not scores:
termcolor.cprint(f"Done, no similarities found.", "yellow")
return

# Get the matching spans, group them per submission
groups = []
pass_to_results = {}
Expand Down
10 changes: 3 additions & 7 deletions compare50/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def compare(scores, ignored_files, pass_):
def missing_spans(file, original_tokens=None, processed_tokens=None):
"""
:param file: file to be examined
:type file: :class:`compare50.File`
:param original_tokens: the unprocessed tokens of ``file``. May be \
:type file: :class:`compare50.File` :param original_tokens: the unprocessed tokens of ``file``. May be \
optionally specified if ``file`` has been tokenized elsewhere to avoid \
tokenizing it again.
:param processed_tokens: the result of preprocessing the tokens of ``file``. \
Expand Down Expand Up @@ -185,11 +184,8 @@ def expand(span_matches, tokens_a, tokens_b):
def is_subsumed(span, tree):
"""Determine if span is contained by any interval in the tree.
Assumes that tree contains no intersecting intervals"""
intervals = tree[span.start:span.end]
for interval in intervals:
if span.start >= interval.begin and span.end <= interval.end:
return True
return False
return any(i.begin <= span.start and i.end >= span.end
for i in tree[span.start:span.end])


def _expand_side(cursor_a, cursor_b, step):
Expand Down
6 changes: 5 additions & 1 deletion compare50/_renderer/static/match.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pre {
counter-reset: none;
}

.file_name {
word-break: break-word;
}

/* highlighted code fragments */
.match {
background-color: #ffd0a8;
Expand Down Expand Up @@ -135,7 +139,7 @@ pre {
margin-bottom: 10%;
}

#next_group {
.matches_group {
margin-bottom: .4em;
}

Expand Down
45 changes: 34 additions & 11 deletions compare50/_renderer/static/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,26 @@ function init_group_button(groups, view_name) {
}

// init group counter
let group_index = 0;
update_group_counter();
let group_index = -1;
go_to_adjacent_group(new Event("InitializeHighlights"), 1);

function go_to_next_group(event) {
function go_to_adjacent_group(event, direction) {
// if view is not active (current), nothing to do here
if (CURRENT_VIEW !== view_name) {
return;
}

// increment index
group_index += direction;

// wrap around
if (group_index >= sorted_groups.length) {
group_index = 0;
}
else if (group_index < 0) {
group_index = sorted_groups.length - 1;
}

update_group_counter();

// find first fragment of group
Expand All @@ -241,18 +252,30 @@ function init_group_button(groups, view_name) {

// scroll to frag
frag.scroll_to();

// increment index
group_index = (group_index + 1) % sorted_groups.length;

}

// On click move to next group from sorted_groups
let next_group_button = document.getElementById("next_group");
next_group_button.addEventListener("click", go_to_next_group);
next_group_button.addEventListener("click", (event) => {
go_to_adjacent_group(event, 1);
});
document.addEventListener("keyup", (event) => {
if (event.key === ' ' || event.key == "]") {
event.preventDefault();
go_to_adjacent_group(event, 1);
}
});

// On click move to previous group from sorted_groups
let previous_group_button = document.getElementById("previous_group");
previous_group_button.addEventListener("click", (event) => {
go_to_adjacent_group(event, -1);
});
document.addEventListener("keyup", (event) => {
if (event.key === ' ') {
event.preventDefault()
go_to_next_group(event);
// left bracket key will go to previous group
if (event.key === "[") {
event.preventDefault();
go_to_adjacent_group(event, -1);
}
});
}
Expand Down
7 changes: 5 additions & 2 deletions compare50/_renderer/templates/match_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ <h4><a href="index.html" class="index-link"><b>compare50</b></a></h4>
{% endfor %}
</div>
<div id="group_nav">
<button type="button" class="btn btn-outline-light next_group" id="next_group">next</button>
<div class="text-light" id="group_counter"></div>
<div class="btn-group" role="group" aria-label="NextPrevGroup">
<button type="button" class="btn btn-outline-light matches_group" id="previous_group">&lt;</button>
<button type="button" class="btn btn-outline-light matches_group" id="next_group">&gt;</button>
</div>
<div class="text-light" id="group_counter"></div>
</div>
</nav>
<div id="content">
Expand Down
5 changes: 3 additions & 2 deletions compare50/comparators/_winnowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ def files(subs):
bar.reset(total=math.ceil((len(submission_files) + len(archive_files) + len(ignored_files)) / 0.9))
frequency_map = collections.Counter()
with _api.Executor() as executor:

# Subs and archive subs
for index, files in ((submission_index, submission_files), (archive_index, archive_files)):
for idx in executor.map(self._index_file(ScoreIndex, (self.k, self.t)), files):
for hash_ in idx.keys():
frequency_map[hash_] += 1
index.include_all(idx)
bar.update()

# Ignored files
for idx in executor.map(self._index_file(ScoreIndex, (self.k, self.t)), ignored_files):
index.include_all(idx)
ignored_index.include_all(idx)
bar.update()


submission_index.ignore_all(ignored_index)
archive_index.ignore_all(ignored_index)

Expand Down
3 changes: 0 additions & 3 deletions docs/requirements.txt

This file was deleted.

Loading

0 comments on commit 912511d

Please sign in to comment.