Skip to content

Commit

Permalink
[#944] Change to originality score and new threshold value (#2072)
Browse files Browse the repository at this point in the history
* [#2027] Fix date range bug (#2034)

Currently, users are unable to select a zoom range that includes 
the until date.

This results in misleading data being presented to users.

* [#2039] Update cypress minimum requirement to 12.15.0 (#2041)

Chrome bug is causing cypress to fail to open a browser on Github 
Actions, causing frontend tests and CI to fail. Upgrading cypress 
to greater than 12.15.0 will fix this issue.

Let's upgrade cypress to fix the failing CI.

* [#1936] Migrate c-segment.vue to typescript (#2035)

Currently, there is still some JavaScript code which remains 
unmigrated. This allows for type unsafe code to be written, 
potentially resulting in unintended behavior.

Let's migrate the rest of the JavaScript code to TypeScript 
code to facilitate future changes to the code.

* [#1936] Migrate load-font-awesome-icons.js to typescript (#2040)

Currently, there is still some JavaScript code which remains 
unmigrated. This allows for type unsafe code to be written, 
potentially resulting in unintended behavior.

Let's migrate the rest of the JavaScript code to TypeScript 
code to facilitate future changes to the code.

* [#2045] Fix cypress zoom feature test (#2047)

Currently, Cypress zoom feature tests are failing due to a recent change
in behavior caused by a bug fix. With the tests failing, we are unable
to detect any future regressions.

Let's update the Cypress tests to test for the new intended behavior.

* [#1936] Migrate random-color-gen.js to typescript (#2043)

Currently, there is still some JavaScript code which remains unmigrated.
This allows for type unsafe code to be written, potentially resulting in
unintended behavior.

Let's migrate random-color-generator.js JavaScript code to TypeScript
code to facilitate future changes to the code.

* [#1936] Migrate c-segment-collection.vue to typescript (#2036)

Currently, there is still some JavaScript code which remains unmigrated.
This allows for type unsafe code to be written, potentially resulting in
unintended behavior.

Let's migrate the rest of the JavaScript code to TypeScript code to
facilitate future changes to the code.

* [#1936] Migrate c-resizer.vue to typescript (#2038)

Currently, there is still some JavaScript code which remains unmigrated.
This allows for type unsafe code to be written, potentially resulting in
unintended behavior.

Let's migrate the rest of the JavaScript code to TypeScript code to
facilitate future changes to the code.

* Bump zod from 3.20.6 to 3.22.3 in /frontend (#2048)

Bumps [zod](https://github.com/colinhacks/zod) from 3.20.6 to 3.22.3.
- [Release notes](https://github.com/colinhacks/zod/releases)
- [Changelog](https://github.com/colinhacks/zod/blob/master/CHANGELOG.md)
- [Commits](colinhacks/zod@v3.20.6...v3.22.3)

---
updated-dependencies:
- dependency-name: zod
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @cypress/request and cypress in /frontend/cypress (#2042)

Bumps [@cypress/request](https://github.com/cypress-io/request) to 3.0.1 and updates ancestor dependency [cypress](https://github.com/cypress-io/cypress). These dependencies need to be updated together.


Updates `@cypress/request` from 2.88.12 to 3.0.1
- [Release notes](https://github.com/cypress-io/request/releases)
- [Changelog](https://github.com/cypress-io/request/blob/master/CHANGELOG.md)
- [Commits](cypress-io/request@v2.88.12...v3.0.1)

Updates `cypress` from 12.17.4 to 13.3.0
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/CHANGELOG.md)
- [Commits](cypress-io/cypress@v12.17.4...v13.3.0)

---
updated-dependencies:
- dependency-name: "@cypress/request"
  dependency-type: indirect
- dependency-name: cypress
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [#1936] Migrate c-ramp.vue to typescript (#2037)

Currently, there is still some JavaScript code which remains unmigrated.
This allows for type unsafe code to be written, potentially resulting in
unintended behavior.

Let's migrate the rest of the JavaScript code to TypeScript code to
facilitate future changes to the code.

* Give partial credit if annotated author is not the same as the blame
author

* [#2054] Fix zoom view bug (#2055)

Currently, when granularity is set to day or week, clicking on a ramp
will open up a zoom view where commit messages are not being displayed
and sorting by insertions does not result in any sorting. 

Let's fix the unintended behaviour of the zoom view.

* [#1936] Migrate repo-sorter.js to typescript (#2052)

Currently, there is still some JavaScript code which remains unmigrated.
This allows for type unsafe code to be written, potentially resulting in
unintended behavior.

Let's migrate repo-sorter.js to TypeScript code to facilitate future
changes to the code.

* [#1936] Migrate safari_date.js to typescript (#2053)

Currently, there is still some JavaScript code which remains unmigrated.
This allows for type unsafe code to be written, potentially resulting in
unintended behavior.

Let's migrate safari_date.js to TypeScript code to facilitate future
changes to the code.

* Remove frontend JS lint (#2063)

Currently, frontend linter is failing due to lint scripts 
checking javascript files, the last of which has been 
removed in PR #2053.

Lets update the lint command to exclude javascript 
files front the check.

* use full and partial credit color

* [#1929] Add dynamic positioning support for tooltips (#2056)

Currently, most tooltips are shown above buttons and text. 
When these tooltips appear at the top of the viewport, 
part of the tooltips will not be rendered.

Let's implement changes such that these tooltips appear below the
text or button, when appearing at the top of the viewport.

* Add test cases for annotated author overriding last author's credit

* revert merge from master

* revert merge from master 58b7002

* [#1928] Fix tooltip zIndex such that it doesn't occlude next file title (#2057)

Currently, if one hovers over a tooltip of the pinned title of
a file whose content is scrolled almost completely, such that 
the title of the next file is just below the pinned title, the 
tooltip is not displayed appropriately, as the title of the next 
file obstructs it.

Let's fix this issue.

* [#1726] Update GitHub-specific references in codebase and docs (#2050)

There are still leftover references specific to GitHub on parts of 
the codebase and docs that have been generalized to accept 
other remote git hosts. 

Let's update these GitHub references to use more general language.

* Trigger workflow

* Revert "Merge branch 'master' into 944-analyze-authorship"

This reverts commit 950c912, reversing
changes made to 4bd05a7.

* fix frontend test failing

* switch to originality score and threshold

* update originality threshold

* revert frontend code changes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: jq1836 <[email protected]>
Co-authored-by: Chan Jun Da <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Pratham Jain <[email protected]>
  • Loading branch information
5 people committed Jan 8, 2024
1 parent 086a64b commit c85423e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
48 changes: 25 additions & 23 deletions src/main/java/reposense/authorship/analyzer/AuthorshipAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class AuthorshipAnalyzer {
private static final Logger logger = LogsManager.getLogger(AuthorshipAnalyzer.class);

private static final double SIMILARITY_THRESHOLD = 0.8;
private static final double ORIGINALITY_THRESHOLD = 0.51;

private static final String DIFF_FILE_CHUNK_SEPARATOR = "\ndiff --git a/.*\n";
private static final Pattern FILE_CHANGED_PATTERN =
Expand Down Expand Up @@ -55,10 +55,10 @@ public static boolean analyzeAuthorship(RepoConfiguration config, String filePat
return true;
}

CandidateLine deletedLine = getDeletedLineWithHighestSimilarity(config, filePath, lineContent, commitHash);
CandidateLine deletedLine = getDeletedLineWithLowestOriginality(config, filePath, lineContent, commitHash);

// Give full credit if there are no deleted lines found or deleted line is less than similarity threshold
if (deletedLine == null || deletedLine.getSimilarityScore() < SIMILARITY_THRESHOLD) {
// Give full credit if there are no deleted lines found or deleted line is more than originality threshold
if (deletedLine == null || deletedLine.getOriginalityScore() > ORIGINALITY_THRESHOLD) {
return true;
}

Expand All @@ -84,14 +84,14 @@ public static boolean analyzeAuthorship(RepoConfiguration config, String filePat
}

/**
* Returns the deleted line in {@code commitHash} that has the highest similarity with {@code lineContent}.
* Returns the deleted line in {@code commitHash} that has the lowest originality with {@code lineContent}.
*/
private static CandidateLine getDeletedLineWithHighestSimilarity(RepoConfiguration config, String filePath,
private static CandidateLine getDeletedLineWithLowestOriginality(RepoConfiguration config, String filePath,
String lineContent, String commitHash) {
String gitLogResults = GitLog.getParentCommits(config.getRepoRoot(), commitHash);
String[] parentCommits = gitLogResults.split(" ");

CandidateLine highestSimilarityLine = null;
CandidateLine lowestOriginalityLine = null;

for (String parentCommit : parentCommits) {
// Generate diff between commit and parent commit
Expand All @@ -112,28 +112,28 @@ private static CandidateLine getDeletedLineWithHighestSimilarity(RepoConfigurati
continue;
}

CandidateLine candidateLine = getDeletedLineWithHighestSimilarityInDiff(
CandidateLine candidateLine = getDeletedLineWithLowestOriginalityInDiff(
fileDiffResult, lineContent, parentCommit, preImageFilePath);
if (candidateLine == null) {
continue;
}

if (highestSimilarityLine == null
|| candidateLine.getSimilarityScore() > highestSimilarityLine.getSimilarityScore()) {
highestSimilarityLine = candidateLine;
if (lowestOriginalityLine == null
|| candidateLine.getOriginalityScore() < lowestOriginalityLine.getOriginalityScore()) {
lowestOriginalityLine = candidateLine;
}
}
}

return highestSimilarityLine;
return lowestOriginalityLine;
}

/**
* Returns the deleted line in {@code fileDiffResult} that has the highest similarity with {@code lineContent}.
* Returns the deleted line in {@code fileDiffResult} that has the lowest originality with {@code lineContent}.
*/
private static CandidateLine getDeletedLineWithHighestSimilarityInDiff(String fileDiffResult, String lineContent,
private static CandidateLine getDeletedLineWithLowestOriginalityInDiff(String fileDiffResult, String lineContent,
String commitHash, String filePath) {
CandidateLine highestSimilarityLine = null;
CandidateLine lowestOriginalityLine = null;

String[] hunks = fileDiffResult.split(HUNK_SEPARATOR);

Expand All @@ -155,11 +155,13 @@ private static CandidateLine getDeletedLineWithHighestSimilarityInDiff(String fi

if (lineChanged.startsWith(DELETED_LINE_SYMBOL)) {
String deletedLineContent = lineChanged.substring(DELETED_LINE_SYMBOL.length());
double similarityScore = similarityScore(lineContent, deletedLineContent);
double originalityScore = computeOriginalityScore(lineContent, deletedLineContent);

if (highestSimilarityLine == null || similarityScore > highestSimilarityLine.getSimilarityScore()) {
highestSimilarityLine = new CandidateLine(
currentPreImageLineNumber, deletedLineContent, filePath, commitHash, similarityScore);
if (lowestOriginalityLine == null
|| originalityScore < lowestOriginalityLine.getOriginalityScore()) {
lowestOriginalityLine = new CandidateLine(
currentPreImageLineNumber, deletedLineContent, filePath, commitHash,
originalityScore);
}
}

Expand All @@ -169,7 +171,7 @@ private static CandidateLine getDeletedLineWithHighestSimilarityInDiff(String fi
}
}

return highestSimilarityLine;
return lowestOriginalityLine;
}

/**
Expand All @@ -191,11 +193,11 @@ private static int getPreImageStartingLineNumber(String linesChangedHeader) {
}

/**
* Calculates the similarity score of {@code s} with {@code baseString}.
* Calculates the originality score of {@code s} with {@code baseString}.
*/
private static double similarityScore(String s, String baseString) {
private static double computeOriginalityScore(String s, String baseString) {
double levenshteinDistance = StringsUtil.getLevenshteinDistance(s, baseString);
return 1 - (levenshteinDistance / baseString.length());
return levenshteinDistance / baseString.length();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/reposense/authorship/model/CandidateLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class CandidateLine {
private final String lineContent;
private final String filePath;
private final String gitBlameCommitHash;
private final double similarityScore;
private final double originalityScore;

public CandidateLine(int lineNumber, String lineContent, String filePath, String gitBlameCommitHash,
double similarityScore) {
double originalityScore) {
this.lineNumber = lineNumber;
this.lineContent = lineContent;
this.filePath = filePath;
this.gitBlameCommitHash = gitBlameCommitHash;
this.similarityScore = similarityScore;
this.originalityScore = originalityScore;
}

public int getLineNumber() {
Expand All @@ -35,7 +35,7 @@ public String getGitBlameCommitHash() {
return gitBlameCommitHash;
}

public double getSimilarityScore() {
return similarityScore;
public double getOriginalityScore() {
return originalityScore;
}
}

0 comments on commit c85423e

Please sign in to comment.