Skip to content

Commit 739babe

Browse files
committed
refactor: standardize Python codebase to snake_case naming conventions
Comprehensive refactoring to follow PEP 8 naming conventions throughout the entire Python codebase. All functions, variables, parameters, files, and directories now use snake_case instead of camelCase. - device.py: processInputFileToEpoch → process_input_file_to_epoch - classification.py: activityClassification → activity_classification - summarisation.py: getActivitySummary → get_activity_summary - circadian.py: calculatePSD → calculate_psd - utils.py: toScreen → to_screen, writeCmds → write_cmds - And 40+ more function renames across all modules - All camelCase parameters converted to snake_case - Function parameters: epochPeriod → epoch_period, startTime → start_time - Local variables: outputFolder → output_folder, summaryVals → summary_vals - Improved single-char variables: e → epoch_data (in circadian.py, utils.py) - accProcess.py → acc_process.py - accPlot.py → acc_plot.py - accWriteCmds.py → acc_write_cmds.py - accCollateSummary.py → acc_collate_summary.py - activityModels/ → activity_models/ - referenceFiles/ → reference_files/ - Fixed 74 E128 indentation issues (autopep8) - Fixed 9 E226/E225 whitespace issues - Fixed 4 W293 blank line whitespace issues - Added noqa comments for acceptable complexity warnings - Zero linting warnings remaining - setup.py: Updated all entry points - MANIFEST.in: Updated package data paths - tests/: Updated 18 test files - docs/: Updated documentation references **CLI Interface**: PRESERVED - All argparse argument names remain camelCase for backward compatibility (e.g., --epochPeriod, --startTime) **Output Keys**: PRESERVED - Dictionary keys in summary output unchanged (e.g., 'file-startTime', 'calibration-xOffset(g)') ✅ All 68 tests passing (6 skipped as expected) ✅ End-to-end processing verified with sample.cwa.gz ✅ Zero linting errors/warnings (make lint) ✅ Package reinstallation successful 16 files changed, 1086 insertions(+), 1080 deletions(-)
1 parent 2bd3ca5 commit 739babe

21 files changed

Lines changed: 1086 additions & 1080 deletions

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include src/accelerometer/activityModels/README.md
1+
include src/accelerometer/activity_models/README.md
22
include src/accelerometer/java/README.md
33
include src/accelerometer/java/*.java
44
include src/accelerometer/java/*.class

docs/source/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@
114114

115115
# latex_elements = {
116116
# The paper size ('letterpaper' or 'a4paper').
117-
117+
118118
# 'papersize': 'letterpaper',
119119

120120
# The font size ('10pt', '11pt' or '12pt').
121-
121+
122122
# 'pointsize': '10pt',
123123

124124
# Additional stuff for the LaTeX preamble.
125-
125+
126126
# 'preamble': '',
127127

128128
# Latex figure (float) alignment
129-
129+
130130
# 'figure_align': 'htbp',
131131
# }
132132

docs/source/usage.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ assess the model:
217217
.. code-block:: python
218218
219219
import accelerometer
220-
from accelerometer.classification import trainClassificationModel
221-
trainClassificationModel( \
220+
from accelerometer.classification import train_classification_model
221+
train_classification_model( \
222222
"labelled-acc-epochs.csv", \
223-
featuresTxt="features.txt", \
224-
testParticipants="4,5", \
223+
features_txt="features.txt", \
224+
test_participants="4,5", \
225225
outputPredict="test-predictions.csv", \
226226
rfTrees=1000, rfThreads=1)
227227
# <Test predictions written to: test-predictions.csv>
@@ -242,7 +242,7 @@ can then be calculated from the test predictions csv file:
242242
yTrueCol = 'label'
243243
yPredCol = 'predicted'
244244
participantCol = 'participant'
245-
classification.perParticipantSummaryHTML(data, yTrueCol, yPredCol,
245+
classification.per_participant_summary_html(data, yTrueCol, yPredCol,
246246
participantCol, htmlFile)
247247
248248
After evaluating the performance of our model on unseen data, we then re-train
@@ -252,12 +252,12 @@ the amount of training data for the final model. This results in an output .tar
252252

253253
.. code-block:: python
254254
255-
from accelerometer.classification import trainClassificationModel
256-
trainClassificationModel( \
255+
from accelerometer.classification import train_classification_model
256+
train_classification_model( \
257257
"labelled-acc-epochs.csv", \
258-
featuresTxt="features.txt", \
258+
features_txt="features.txt", \
259259
rfTrees=1000, rfThreads=1, \
260-
testParticipants=None, \
260+
test_participants=None, \
261261
outputModel="custom-model.tar")
262262
# <Model saved to custom-model.tar>
263263
@@ -280,7 +280,7 @@ to test the performance of a model trained on unseen data for each participant:
280280
.. code-block:: python
281281
282282
import pandas as pd
283-
from acceleration.classification import trainClassificationModel
283+
from acceleration.classification import train_classification_model
284284
285285
trainingFile = "labelled-acc-epochs.csv"
286286
d = pd.read_csv(trainingFile, usecols=['participant'])
@@ -289,11 +289,11 @@ to test the performance of a model trained on unseen data for each participant:
289289
w = open('training-cmds.txt','w')
290290
for p in pts:
291291
cmd = "import accelerometer;"
292-
cmd += "trainClassificationModel("
292+
cmd += "train_classification_model("
293293
cmd += "'" + trainingFile + "', "
294-
cmd += "featuresTxt='features.txt',"
295-
cmd += "testParticipants='" + str(p) + "',"
296-
cmd += "labelCol='label',"
294+
cmd += "features_txt='features.txt',"
295+
cmd += "test_participants='" + str(p) + "',"
296+
cmd += "label_col='label',"
297297
cmd += "outputPredict='testPredict-" + str(p) + ".csv',"
298298
cmd += "rfTrees=100, rfThreads=1)"
299299
w.write('python3 -c $"' + cmd + '"\n')

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ def get_string(string, rel_path="src/accelerometer/__init__.py"):
8787
},
8888
entry_points={
8989
"console_scripts": [
90-
"accProcess=accelerometer.accProcess:main",
91-
"accPlot=accelerometer.accPlot:main",
92-
"accWriteCmds=accelerometer.accWriteCmds:main",
93-
"accCollateSummary=accelerometer.accCollateSummary:main"
90+
"accProcess=accelerometer.acc_process:main",
91+
"accPlot=accelerometer.acc_plot:main",
92+
"accWriteCmds=accelerometer.acc_write_cmds:main",
93+
"accCollateSummary=accelerometer.acc_collate_summary:main"
9494
]
9595
},
9696
)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import argparse
2-
from accelerometer.utils import collateSummary
2+
from accelerometer.utils import collate_summary
33

44

55
def main():
@@ -8,8 +8,8 @@ def main():
88
parser.add_argument('--outputCsvFile', '-o', default="all-summary.csv")
99
args = parser.parse_args()
1010

11-
collateSummary(resultsDir=args.resultsDir,
12-
outputCsvFile=args.outputCsvFile)
11+
collate_summary(results_dir=args.resultsDir,
12+
output_csv_file=args.outputCsvFile)
1313

1414

1515
if __name__ == '__main__':
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ def main(): # noqa: C901
6262
if len(sys.argv) < 2:
6363
msg = "\nInvalid input, please enter at least 1 parameter, e.g."
6464
msg += "\npython accPlot.py timeSeries.csv.gz \n"
65-
utils.toScreen(msg)
65+
utils.to_screen(msg)
6666
parser.print_help()
6767
sys.exit(-1)
6868
args = parser.parse_args()
6969

7070
# determine output file name
7171
if args.plotFile is None:
72-
inputFileFolder, inputFileName = os.path.split(args.timeSeriesFile)
73-
inputFileName = inputFileName.split('.')[0] # remove any extension
74-
args.plotFile = os.path.join(inputFileFolder, inputFileName + "-plot.png")
72+
input_file_folder, input_file_name = os.path.split(args.timeSeriesFile)
73+
input_file_name = input_file_name.split('.')[0] # remove any extension
74+
args.plotFile = os.path.join(input_file_folder, input_file_name + "-plot.png")
7575

7676
# read time series file to pandas DataFrame
7777
data = pd.read_csv(
@@ -88,15 +88,15 @@ def main(): # noqa: C901
8888
title = args.timeSeriesFile if args.showFileName else None
8989

9090
# call plot function and save figure
91-
fig = plotTimeSeries(data, title=title, showFirstNDays=args.showFirstNDays)
91+
fig = plot_time_series(data, title=title, show_first_n_days=args.showFirstNDays)
9292
fig.savefig(args.plotFile, dpi=200, bbox_inches='tight')
9393
print('Plot file written to:', args.plotFile)
9494

9595

96-
def plotTimeSeries( # noqa: C901
96+
def plot_time_series( # noqa: C901
9797
data,
9898
title=None,
99-
showFirstNDays=None
99+
show_first_n_days=None
100100
):
101101
"""
102102
Plot acceleration traces and classified activities.
@@ -110,18 +110,18 @@ def plotTimeSeries( # noqa: C901
110110
:type data: pd.DataFrame
111111
:param title: Optional plot title
112112
:type title: str, optional
113-
:param showFirstNDays: Only show first n days of time series (if specified)
114-
:type showFirstNDays: int, optional
113+
:param show_first_n_days: Only show first n days of time series (if specified)
114+
:type show_first_n_days: int, optional
115115
:return: pyplot Figure
116116
:rtype: plt.Figure
117117
118118
:Example:
119119
120120
.. code-block:: python
121121
122-
from accelerometer.accPlot import plotTimeSeries
122+
from accelerometer.accPlot import plot_time_series
123123
df = pd.DataFrame(...)
124-
fig = plotTimeSeries(df)
124+
fig = plot_time_series(df)
125125
fig.show()
126126
"""
127127

@@ -146,8 +146,8 @@ def plotTimeSeries( # noqa: C901
146146
new_index = pd.date_range(data.index[0], data.index[-1], freq=freq)
147147
data = data.reindex(new_index, method='nearest', tolerance=freq, fill_value=np.NaN)
148148

149-
if showFirstNDays is not None:
150-
data = data.first(str(showFirstNDays) + 'D')
149+
if show_first_n_days is not None:
150+
data = data.first(str(show_first_n_days) + 'D')
151151

152152
labels = [label for label in LABELS_AND_COLORS.keys() if label in data.columns]
153153
colors = [LABELS_AND_COLORS[label] for label in labels]
@@ -166,8 +166,8 @@ def plotTimeSeries( # noqa: C901
166166
data[labels] = data[labels].astype('f4') * MAXRANGE
167167

168168
# number of rows to display in figure (all days + legend)
169-
groupedDays = data.groupby(data.index.date)
170-
nrows = len(groupedDays) + 1
169+
grouped_days = data.groupby(data.index.date)
170+
nrows = len(grouped_days) + 1
171171

172172
# create overall figure
173173
fig = plt.figure(None, figsize=(10, nrows), dpi=100)
@@ -177,7 +177,7 @@ def plotTimeSeries( # noqa: C901
177177
# create individual plot for each day
178178
i = 0
179179
axs = []
180-
for day, group in groupedDays:
180+
for day, group in grouped_days:
181181

182182
ax = fig.add_subplot(nrows, 1, i + 1)
183183

@@ -244,8 +244,8 @@ def plotTimeSeries( # noqa: C901
244244
# format x-axis to show hours
245245
fig.autofmt_xdate()
246246
# add hour labels to top of plot
247-
hrLabels = ['00:00', '04:00', '08:00', '12:00', '16:00', '20:00', '24:00']
248-
axs[0].set_xticklabels(hrLabels)
247+
hr_labels = ['00:00', '04:00', '08:00', '12:00', '16:00', '20:00', '24:00']
248+
axs[0].set_xticklabels(hr_labels)
249249
axs[0].tick_params(labelbottom=False, labeltop=True, labelleft=False)
250250

251251
# auto trim borders

0 commit comments

Comments
 (0)