Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor variable naming #114

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
20 changes: 10 additions & 10 deletions src/main/java/edu/ie3/tools/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ private void convert() {
ZonedDateTime newestPossibleModelrun =
(ZonedDateTime)
dbController.execSingleResultNamedQuery(
FileModel.NewestDownloadedModelrun, Collections.emptyList());
FileModel.NEWEST_DOWNLOADED_MODELRUN, Collections.emptyList());

// retrieves the starting modelrun ( = oldest modelrun where persisted==false or no converter
// run info available)
ZonedDateTime currentModelrun =
(ZonedDateTime)
dbController.execSingleResultNamedQuery(
FileModel.OldestModelrunWithUnprocessedFiles, Collections.emptyList());
FileModel.OLDEST_MODELRUN_WITH_UNPROCESSED_FILES, Collections.emptyList());

if (currentModelrun != null) {
coordinates = getCoordinates();
Expand Down Expand Up @@ -189,11 +189,11 @@ private void openArchiveFiles(ZonedDateTime currentModelrun, int timestep) {
FileModel.class, FileModel.createFileName(currentModelrun, timestep, param));
if (file != null) {
files.add(file);
if (file.isSufficient_size() && (file.isValid_file() == null || file.isValid_file())) {
if (!file.isPersisted() && !file.isArchivefile_deleted() && !file.isDecompressed()) {
if (file.isSufficientSize() && (file.isValidFile() == null || file.isValidFile())) {
if (!file.isPersisted() && !file.isArchiveFileDeleted() && !file.isDecompressed()) {
tasks.add(new Decompressor(file, folderpath));
}
} else if (file.getDownload_fails() > 3
} else if (file.getDownloadFails() > 3
|| file.getModelrun().isBefore(ZonedDateTime.now().minusDays(1))) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaTimeDefaultTimeZone: ZonedDateTime.now() is not allowed because it silently uses the system default time-zone. You must pass an explicit time-zone (e.g., ZoneId.of("America/Los_Angeles")) to this method.

Suggested change
|| file.getModelrun().isBefore(ZonedDateTime.now().minusDays(1))) {
|| file.getModelrun().isBefore(ZonedDateTime.now(ZoneId.systemDefault()).minusDays(1))) {

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

if (edu.ie3.tools.Main.deleteDownloadedFiles) {
logger.trace(
Expand All @@ -218,10 +218,10 @@ private void openArchiveFiles(ZonedDateTime currentModelrun, int timestep) {
}
files.forEach(
file -> {
if (file.isDecompressed() && (file.isValid_file() == null || file.isValid_file()))
if (file.isDecompressed() && (file.isValidFile() == null || file.isValidFile()))
parameterLevelToFile.put(file.getParameter(), file);
else {
file.setValid_file(false);
file.setValidFile(false);
fileStatusLogger.trace(
file.getName() + " | vff | valid_file = false | Decompression failed");
}
Expand Down Expand Up @@ -295,10 +295,10 @@ public void convertTimeStep(ZonedDateTime modelRun, int timeStep, String folderP

// update the file model information about the validity of the extractor result
FileModel file = parameterLevelToFile.get(extractorResult.getParameter());
file.setValid_file(extractorResult.isValidFile());
file.setValidFile(extractorResult.isValidFile());
fileStatusLogger.trace(
file.getName()
+ (Boolean.TRUE.equals(file.isValid_file())
+ (Boolean.TRUE.equals(file.isValidFile())
? " | vft | valid_file = true | Extraction"
: " | vff | valid_file = false | Extraction"));

Expand Down Expand Up @@ -371,7 +371,7 @@ private void validation() {
for (Map.Entry<Parameter, FileModel> entry : parameterLevelToFile.entrySet()) {
FileModel file = entry.getValue();
double relAmountMissingCoordinates =
((double) file.getMissing_coordinates()) / coordinates.size();
((double) file.getMissingCoordinates()) / coordinates.size();
if (relAmountMissingCoordinates < edu.ie3.tools.Main.faultTolerance) {
file.setPersisted(true);
fileStatusLogger.trace(file.getName() + " | pf | persisted = true | Validation");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/ie3/tools/Decompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static boolean decompress(@NotNull FileModel file, String folderpath) {
Parameter parameter = file.getParameter();
logger.warn(
Converter.getFormattedTimestep(file) + "File not found for parameter " + parameter);
file.setArchivefile_deleted(true);
file.setArchiveFileDeleted(true);
filestatusLogger.trace(
file.getName() + " | adt | archivefile_deleted = true | File not Found");

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/edu/ie3/tools/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void run() {
ZonedDateTime newestDateDownloaded = earliestPossibleModelrun;
List<FileModel> failedDownloads =
dbController.execNamedQuery(
FileModel.FailedDownloads, Collections.singletonList(earliestPossibleModelrun));
FileModel.FAILED_DOWNLOADS, Collections.singletonList(earliestPossibleModelrun));
for (FileModel file : failedDownloads) {
ZonedDateTime modelrun = file.getModelrun();
if (modelrun.isAfter(newestDateDownloaded)) {
Expand Down Expand Up @@ -181,7 +181,7 @@ public boolean download(ZonedDateTime modelrun, Parameter param) {
*/
public boolean downloadFile(String folder, FileModel filemodel) {
boolean success = false;
if (!filemodel.isSufficient_size() && filemodel.getDownload_fails() < 3) {
if (!filemodel.isSufficientSize() && filemodel.getDownloadFails() < 3) {
String url = filemodel.getURL();
try {
if (isUrlReachable(url)) {
Expand All @@ -193,15 +193,15 @@ public boolean downloadFile(String folder, FileModel filemodel) {
success = false;
logger.warn("File " + filemodel.getName() + " is too small (" + file.length() + "B)");
} else {
filemodel.setSufficient_size(true);
filemodel.setSufficientSize(true);
filestatusLogger.trace(
file.getName() + " | ss | sufficient_size = true | Download success");

filemodel.setDownload_date(ZonedDateTime.now());
filemodel.setDownloadDate(ZonedDateTime.now());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaTimeDefaultTimeZone: ZonedDateTime.now() is not allowed because it silently uses the system default time-zone. You must pass an explicit time-zone (e.g., ZoneId.of("America/Los_Angeles")) to this method. (details)

Suggested change
filemodel.setDownloadDate(ZonedDateTime.now());
filemodel.setDownloadDate(ZonedDateTime.now(ZoneId.systemDefault()));

(at-me in a reply with help or ignore)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaTimeDefaultTimeZone: ZonedDateTime.now() is not allowed because it silently uses the system default time-zone. You must pass an explicit time-zone (e.g., ZoneId.of("America/Los_Angeles")) to this method.

Suggested change
filemodel.setDownloadDate(ZonedDateTime.now());
filemodel.setDownloadDate(ZonedDateTime.now(ZoneId.systemDefault()));

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

filestatusLogger.trace(
file.getName() + " | dd | Downloadd_date = now | Download success");

filemodel.setArchivefile_deleted(false);
filemodel.setArchiveFileDeleted(false);
filestatusLogger.trace(
file.getName() + " | adf | archivefile_deleted = false | Download success");
success = true;
Expand All @@ -213,7 +213,7 @@ public boolean downloadFile(String folder, FileModel filemodel) {
logger.error("Could not download " + filemodel.getName() + " (" + e.getMessage() + ")");
}
if (!success) {
filemodel.incrementDownload_fails();
filemodel.incrementDownloadFails();
filestatusLogger.trace(
filemodel.getName() + " | idf | incremented download_fails | failed Download");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/ie3/tools/Extractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ private ExtractorResult extractParameters() throws IOException {
// check if file exists in path
File f = file.getGRIB22File(path);
if (!f.exists()) {
file.setGribfile_deleted(true);
file.setGribFileDeleted(true);
f = file.getBZ2File(path);
if (!f.exists()) file.setArchivefile_deleted(true);
if (!f.exists()) file.setArchiveFileDeleted(true);
throw new IOException(
"Could not find file " + file.getName() + " ( " + f.getAbsolutePath() + " )");
}
Expand Down
93 changes: 50 additions & 43 deletions src/main/java/edu/ie3/tools/models/persistence/FileModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
public class FileModel implements Serializable {

/** Selects newest (max) modelrun */
public static final String NewestDownloadedModelrun = "FileModel.NewestDownloadedModelrun";
public static final String NEWEST_DOWNLOADED_MODELRUN = "FileModel.NewestDownloadedModelrun";
/**
* Selects the oldest (min) modelrun, which has a sufficient file size, but hasn't been processed
* yet
*/
public static final String OldestModelrunWithUnprocessedFiles =
public static final String OLDEST_MODELRUN_WITH_UNPROCESSED_FILES =
"FileModel.OldestModelrunWithUnprocessedFiles";
/** Selects files, that have been too small or invalid in previous runs */
public static final String FailedDownloads = "FileModel.FailedDownloads";
public static final String FAILED_DOWNLOADS = "FileModel.FailedDownloads";
/** Selects files, that are invalid and not yet deleted */
public static final String InvalidFiles = "FileModel.InvalidFiles";
public static final String INVALID_FILES = "FileModel.InvalidFiles";

public static final String PREFIX = "icon-eu_europe_regular-lat-lon_";
public static final String PREFIX_SINGLE_LEVEL = PREFIX + "single-level_";
Expand All @@ -69,23 +69,30 @@ public class FileModel implements Serializable {
@Enumerated(EnumType.STRING)
private Parameter parameter;

@Column private int download_fails;
@Column(name = "download_fails")
private int downloadFails;

@Column private boolean sufficient_size;
@Column(name = "sufficient_size")
private boolean sufficientSize;

@Column private ZonedDateTime download_date;
@Column(name = "download_date")
private ZonedDateTime downloadDate;

@Column private boolean decompressed;

@Column private int missing_coordinates;
@Column(name = "missing_coordinates")
private int missingCoordinates;

@Column private Boolean valid_file;
@Column(name = "valid_file")
private Boolean validFile;

@Column private boolean persisted;

@Column private boolean archivefile_deleted;
@Column(name = "archivefile_deleted")
private boolean archiveFileDeleted;

@Column private boolean gribfile_deleted;
@Column(name = "gribfile_deleted")
private boolean isGribFileDeleted;

public FileModel(ZonedDateTime modelrun, int timestep, Parameter parameter) {
this.modelrun = modelrun;
Expand Down Expand Up @@ -134,32 +141,32 @@ public void setParameter(Parameter parameter) {
this.parameter = parameter;
}

public int getDownload_fails() {
return download_fails;
public int getDownloadFails() {
return downloadFails;
}

public void setDownload_fails(int download_fails) {
this.download_fails = download_fails;
public void setDownloadFails(int download_fails) {
this.downloadFails = download_fails;
}

public void incrementDownload_fails() {
this.download_fails++;
public void incrementDownloadFails() {
this.downloadFails++;
}

public boolean isSufficient_size() {
return sufficient_size;
public boolean isSufficientSize() {
return sufficientSize;
}

public void setSufficient_size(boolean sufficient_size) {
this.sufficient_size = sufficient_size;
public void setSufficientSize(boolean sufficient_size) {
this.sufficientSize = sufficient_size;
}

public ZonedDateTime getDownload_date() {
return download_date;
public ZonedDateTime getDownloadDate() {
return downloadDate;
}

public void setDownload_date(ZonedDateTime download_date) {
this.download_date = download_date;
public void setDownloadDate(ZonedDateTime download_date) {
this.downloadDate = download_date;
}

public boolean isDecompressed() {
Expand All @@ -170,24 +177,24 @@ public void setDecompressed(boolean decompressed) {
this.decompressed = decompressed;
}

public int getMissing_coordinates() {
return missing_coordinates;
public int getMissingCoordinates() {
return missingCoordinates;
}

public void setMissing_coordinates(int missing_coordinates) {
this.missing_coordinates = missing_coordinates;
public void setMissingCoordinates(int missingCoordinates) {
this.missingCoordinates = missingCoordinates;
}

public void addMissing_coordinate() {
this.missing_coordinates++;
public void addMissingCoordinate() {
this.missingCoordinates++;
}

public Boolean isValid_file() {
return valid_file;
public Boolean isValidFile() {
return validFile;
}

public void setValid_file(Boolean valid_file) {
this.valid_file = valid_file;
public void setValidFile(Boolean valid_file) {
this.validFile = valid_file;
}

public boolean isPersisted() {
Expand All @@ -198,20 +205,20 @@ public void setPersisted(boolean persisted) {
this.persisted = persisted;
}

public boolean isArchivefile_deleted() {
return archivefile_deleted;
public boolean isArchiveFileDeleted() {
return archiveFileDeleted;
}

public void setArchivefile_deleted(boolean archivefile_deleted) {
this.archivefile_deleted = archivefile_deleted;
public void setArchiveFileDeleted(boolean archiveFileDeleted) {
this.archiveFileDeleted = archiveFileDeleted;
}

public boolean isGribfile_deleted() {
return gribfile_deleted;
public boolean isGribFileDeleted() {
return isGribFileDeleted;
}

public void setGribfile_deleted(boolean gribfile_deleted) {
this.gribfile_deleted = gribfile_deleted;
public void setGribFileDeleted(boolean isGribFileDeleted) {
this.isGribFileDeleted = isGribFileDeleted;
}

public void setModelrun(ZonedDateTime modelrun) {
Expand Down
Loading