Skip to content

Commit

Permalink
Add refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriae committed Feb 27, 2025
1 parent 2546095 commit bb3f9c9
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 85 deletions.
82 changes: 82 additions & 0 deletions .sourcery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 🪄 This is your project's Sourcery configuration file.

# You can use it to get Sourcery working in the way you want, such as
# ignoring specific refactorings, skipping directories in your project,
# or writing custom rules.

# 📚 For a complete reference to this file, see the documentation at
# https://docs.sourcery.ai/Configuration/Project-Settings/

# This file was auto-generated by Sourcery on 2025-02-27 at 18:52.

version: '1' # The schema version of this config file

ignore: # A list of paths or files which Sourcery will ignore.
- .git
- env
- .env
- .tox
- node_modules
- vendor
- venv
- .venv
- ~/.pyenv
- ~/.rye
- ~/.vscode
- .vscode
- ~/.cache
- ~/.config
- ~/.local

rule_settings:
enable:
- default
disable: [] # A list of rule IDs Sourcery will never suggest.
rule_types:
- refactoring
- suggestion
- comment
python_version: '3.9' # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version.

# rules: # A list of custom rules Sourcery will include in its analysis.
# - id: no-print-statements
# description: Do not use print statements in the test directory.
# pattern: print(...)
# language: python
# replacement:
# condition:
# explanation:
# paths:
# include:
# - test
# exclude:
# - conftest.py
# tests: []
# tags: []

# rule_tags: {} # Additional rule tags.

# metrics:
# quality_threshold: 25.0

# github:
# labels: []
# ignore_labels:
# - sourcery-ignore
# request_review: author
# sourcery_branch: sourcery/{base_branch}

# clone_detection:
# min_lines: 3
# min_duplicates: 2
# identical_clones_only: false

# proxy:
# url:
# ssl_certs_file:
# no_ssl_verify: false

# coding_assistant:
# project_description: ''
# enabled: true
# recipe_prompts: {}
76 changes: 37 additions & 39 deletions app/scout/scouting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def get_all_pit_scouting(self, user_team_number=None, user_id=None):
self.ensure_connected()
try:
logger.info(f"Fetching pit scouting data for user_id: {user_id}, team_number: {user_team_number}")

# First check if we have any data at all in the collection
total_count = self.db.pit_scouting.count_documents({})
logger.info(f"Total documents in pit_scouting collection: {total_count}")
Expand All @@ -672,18 +672,6 @@ def get_all_pit_scouting(self, user_team_number=None, user_id=None):
scouter = self.db.users.find_one({"_id": doc['scouter_id']})
logger.info(f"Associated scouter: {scouter}")

pipeline = [
{
"$lookup": {
"from": "users",
"localField": "scouter_id",
"foreignField": "_id",
"as": "scouter"
}
},
{"$unwind": "$scouter"},
]

# Log the user's info
user_info = self.db.users.find_one({"_id": ObjectId(user_id)})
logger.info(f"User info: {user_info}")
Expand All @@ -708,39 +696,49 @@ def get_all_pit_scouting(self, user_team_number=None, user_id=None):
}
}
logger.info("Using individual user filter")

pipeline.append(match_stage)

# Project the needed fields
pipeline.append({
"$project": {
"_id": 1,
"team_number": 1,
"drive_type": 1,
"swerve_modules": 1,
"motor_details": 1,
"motor_count": 1,
"dimensions": 1,
"mechanisms": 1,
"programming_language": 1,
"autonomous_capabilities": 1,
"driver_experience": 1,
"notes": 1,
"created_at": 1,
"updated_at": 1,
"scouter_id": "$scouter._id",
"scouter_name": "$scouter.username",
"scouter_team": "$scouter.teamNumber"
}
})

pipeline = [
{
"$lookup": {
"from": "users",
"localField": "scouter_id",
"foreignField": "_id",
"as": "scouter",
}
},
{"$unwind": "$scouter"},
*(
match_stage,
{
"$project": {
"_id": 1,
"team_number": 1,
"drive_type": 1,
"swerve_modules": 1,
"motor_details": 1,
"motor_count": 1,
"dimensions": 1,
"mechanisms": 1,
"programming_language": 1,
"autonomous_capabilities": 1,
"driver_experience": 1,
"notes": 1,
"created_at": 1,
"updated_at": 1,
"scouter_id": "$scouter._id",
"scouter_name": "$scouter.username",
"scouter_team": "$scouter.teamNumber",
}
},
),
]
# Log the full pipeline for debugging
logger.info(f"MongoDB pipeline: {pipeline}")

# Execute the pipeline on the pit_scouting collection
pit_data = list(self.db.pit_scouting.aggregate(pipeline))
logger.info(f"Retrieved {len(pit_data)} pit scouting records")

# Log the first record if any exist (excluding sensitive info)
if pit_data:
sample_record = pit_data[0].copy()
Expand Down
55 changes: 31 additions & 24 deletions app/static/js/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,9 @@ class Canvas {

// Mouse events for drawing and panning
this.canvas.addEventListener('mousedown', (e) => {
if (this.readonly && !e.shiftKey && e.button !== 1) return; // Only allow panning in readonly mode
if (this.readonly && !e.shiftKey && e.button !== 1) {
return;
} // Only allow panning in readonly mode

this.lastEvent = e;
if (e.shiftKey || e.button === 1) {
Expand Down Expand Up @@ -1070,7 +1072,9 @@ class Canvas {
});

this.canvas.addEventListener('mousemove', (e) => {
if (this.readonly && !this.isPanning) return; // Only handle panning in readonly mode
if (this.readonly && !this.isPanning) {
return;
} // Only handle panning in readonly mode

// Update cursor based on resize handles when in select mode
if (this.currentTool === 'select' && !this.isSelecting && !this.moveSelection.active && !this.resizeHandles.active) {
Expand Down Expand Up @@ -1156,7 +1160,9 @@ class Canvas {
});

this.canvas.addEventListener('mouseup', (e) => {
if (this.readonly && !this.isPanning) return; // Only handle panning in readonly mode
if (this.readonly && !this.isPanning) {
return;
} // Only handle panning in readonly mode

if (this.resizeHandles.active) {
this.resizeHandles.active = false;
Expand Down Expand Up @@ -1261,7 +1267,9 @@ class Canvas {

// Touch events for mobile
this.canvas.addEventListener('touchstart', (e) => {
if (this.readonly && e.touches.length !== 2) return; // Only allow two-finger pan/zoom in readonly mode
if (this.readonly && e.touches.length !== 2) {
return;
} // Only allow two-finger pan/zoom in readonly mode

e.preventDefault();

Expand Down Expand Up @@ -1356,7 +1364,9 @@ class Canvas {
});

this.canvas.addEventListener('touchmove', (e) => {
if (this.readonly && e.touches.length !== 2) return; // Only allow two-finger pan/zoom in readonly mode
if (this.readonly && e.touches.length !== 2) {
return;
} // Only allow two-finger pan/zoom in readonly mode

e.preventDefault();

Expand Down Expand Up @@ -1521,20 +1531,19 @@ class Canvas {

// Add keyboard shortcuts
window.addEventListener('keydown', (e) => {
if (this.readonly) return; // Disable keyboard shortcuts in readonly mode
if (this.readonly) {
return;
} // Disable keyboard shortcuts in readonly mode

if (e.key === 'Escape') {
// Cancel shape drawing or selection
if (this.previewShape || this.selectionRect) {
this.previewShape = null;
this.selectionRect = null;
this.startX = null;
this.startY = null;
this.selectedStrokes = [];
this.redrawCanvas();
this.showStatus('Operation cancelled');
return;
}
if (e.key === 'Escape' && (this.previewShape || this.selectionRect)) {
this.previewShape = null;
this.selectionRect = null;
this.startX = null;
this.startY = null;
this.selectedStrokes = [];
this.redrawCanvas();
this.showStatus('Operation cancelled');
return;
}

if (e.ctrlKey || e.metaKey) { // Support both Windows/Linux and Mac
Expand Down Expand Up @@ -1600,12 +1609,10 @@ class Canvas {
this.setFill(!this.isFilled);
break;
}
} else if (e.key === 'Backspace' || e.key === 'Delete') {
if (this.selectedStrokes.length > 0) {
e.preventDefault();
this.deleteSelectedStrokes();
}
}
} else if ((e.key === 'Backspace' || e.key === 'Delete') && this.selectedStrokes.length > 0) {
e.preventDefault();
this.deleteSelectedStrokes();
}
});
}

Expand Down
4 changes: 3 additions & 1 deletion app/static/js/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ function showAutoPath(pathData, autoNotes, deviceType) {
const container = document.getElementById('autoPathContainer');
const notesElement = document.getElementById('modalAutoNotes');

if (!modal || !container) return;
if (!modal || !container) {
return;
}

modal.classList.remove('hidden');

Expand Down
25 changes: 15 additions & 10 deletions app/static/js/scout/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ document.addEventListener('DOMContentLoaded', function() {
externalUpdateUIControls: updateUIControls,
showStatus: (message) => {
const flashContainer = document.querySelector('.container');
if (!flashContainer) return;
if (!flashContainer) {
return;
}

const messageDiv = document.createElement('div');
messageDiv.className = 'fixed bottom-6 left-1/2 -translate-x-1/2 sm:left-auto sm:right-6 sm:-translate-x-0 z-50 w-[90%] sm:w-full max-w-xl min-h-[60px] sm:min-h-[80px] mx-auto sm:mx-0 animate-fade-in-up';
Expand Down Expand Up @@ -182,7 +184,7 @@ document.addEventListener('DOMContentLoaded', function() {
const thicknessValue = document.getElementById('pathThicknessValue');

thicknessSlider.addEventListener('input', function() {
const value = this.value;
const {value} = this;
thicknessValue.textContent = value;
CanvasField.setThickness(parseInt(value));
});
Expand Down Expand Up @@ -277,7 +279,9 @@ document.addEventListener('DOMContentLoaded', function() {
});

loadFile.addEventListener('change', (e) => {
if (e.target.files.length === 0) return;
if (e.target.files.length === 0) {
return;
}

const file = e.target.files[0];
const reader = new FileReader();
Expand All @@ -301,7 +305,9 @@ document.addEventListener('DOMContentLoaded', function() {

// Add keyboard shortcuts
document.addEventListener('keydown', (e) => {
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
return;
}

if (e.ctrlKey) {
switch (e.key.toLowerCase()) {
Expand Down Expand Up @@ -353,12 +359,11 @@ document.addEventListener('DOMContentLoaded', function() {
e.preventDefault();
e.stopPropagation();
if (e.shiftKey) {
CanvasField.redo();
} else {
if (!e.repeat) { // Only trigger once when key is first pressed
CanvasField.undo();
}
}
CanvasField.redo();
}
else if (!e.repeat) { // Only trigger once when key is first pressed
CanvasField.undo();
}
updatePathData();
break;
case 'y':
Expand Down
Loading

0 comments on commit bb3f9c9

Please sign in to comment.