Skip to content

Commit 2f947a5

Browse files
committed
refactor: add logs
1 parent 7f2aafa commit 2f947a5

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

backend/src/main/java/ch/xxx/trader/usecase/services/CoinbaseService.java

+21-8
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private String createHourDayAvg() {
196196

197197
private void processTimeFrame(MyTimeFrame timeFrame1, boolean isDay) {
198198
Date start = new Date();
199-
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
199+
final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
200200
final var nonZeroProperties = new AtomicInteger(0);
201201
Query query = new Query();
202202
query.addCriteria(
@@ -206,27 +206,40 @@ private void processTimeFrame(MyTimeFrame timeFrame1, boolean isDay) {
206206
Mono<Collection<QuoteCb>> collectCb = this.myMongoRepository.find(query, QuoteCb.class)
207207
.timeout(Duration.ofSeconds(10L)).doOnError(ex -> LOG.warn(logFailed, ex))
208208
.onErrorResume(ex -> Mono.empty()).subscribeOn(this.mongoScheduler).collectList()
209-
.map(quotes -> isDay ? this.makeCbQuoteDay(quotes, timeFrame1.begin(), timeFrame1.end())
210-
: this.makeCbQuoteHour(quotes, timeFrame1.begin(), timeFrame1.end()));
209+
.map(quotes -> this.createCbQuoteTimeFrame(timeFrame1, isDay, quotes));
211210
collectCb.filter(Predicate.not(Collection::isEmpty))
212211
.map(myColl -> this.countRelevantProperties(nonZeroProperties, myColl))
213212
.flatMap(myColl -> this.myMongoRepository.insertAll(Mono.just(myColl), isDay ? CB_DAY_COL : CB_HOUR_COL)
214213
.timeout(Duration.ofSeconds(10L)).doOnError(ex -> LOG.warn(logFailed, ex))
215214
.onErrorResume(ex -> Mono.empty()).subscribeOn(this.mongoScheduler).collectList())
216215
.subscribeOn(this.mongoScheduler).block();
217-
LOG.info(String.format("Prepared Coinbase %s Data for: ", isDay ? "Day" : "Hour") + sdf.format(timeFrame1.begin().getTime()) + " Time: "
218-
+ (new Date().getTime() - start.getTime()) + "ms" + " 0 < properties: " + nonZeroProperties.get());
216+
LOG.info(String.format("Prepared Coinbase %s Data for: ", isDay ? "Day" : "Hour")
217+
+ sdf.format(timeFrame1.begin().getTime()) + " Time: " + (new Date().getTime() - start.getTime()) + "ms"
218+
+ " 0 < properties: " + nonZeroProperties.get());
219+
}
220+
221+
private Collection<QuoteCb> createCbQuoteTimeFrame(final MyTimeFrame timeFrame1, final boolean isDay,
222+
List<QuoteCb> quotes) {
223+
Date start = new Date();
224+
final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
225+
var result = isDay ? this.makeCbQuoteDay(quotes, timeFrame1.begin(), timeFrame1.end())
226+
: this.makeCbQuoteHour(quotes, timeFrame1.begin(), timeFrame1.end());
227+
LOG.info(String.format("Calculate Coinbase %s Data for: ", isDay ? "Day" : "Hour")
228+
+ sdf.format(timeFrame1.begin().getTime()) + " Time: " + (new Date().getTime() - start.getTime()) + "ms");
229+
return result;
219230
}
220231

221232
private void createCbIntervalAvg(boolean isDay) {
222233
LOG.info(isDay ? "createCbDailyAvg()" : "createCbHourlyAvg()");
223234
LocalDateTime startAll = LocalDateTime.now();
224-
final MyTimeFrame timeFrame = this.serviceUtils.createTimeFrame(isDay ? CB_DAY_COL : CB_HOUR_COL, QuoteCb.class, false);
235+
final MyTimeFrame timeFrame = this.serviceUtils.createTimeFrame(isDay ? CB_DAY_COL : CB_HOUR_COL, QuoteCb.class,
236+
false);
225237
final Calendar now = Calendar.getInstance();
226238
now.setTime(Date.from(LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
227-
this.createTimeFrames(timeFrame, now).stream().forEachOrdered(timeFrame1 -> this.processTimeFrame(timeFrame1, isDay));
239+
this.createTimeFrames(timeFrame, now).stream()
240+
.forEachOrdered(timeFrame1 -> this.processTimeFrame(timeFrame1, isDay));
228241
var logStmt = String.format("Prepared Coinbase %s Data Time:", isDay ? "Daily" : "Hourly");
229-
LOG.info(this.serviceUtils.createAvgLogStatement(startAll, logStmt));
242+
LOG.info(this.serviceUtils.createAvgLogStatement(startAll, logStmt));
230243
}
231244

232245
private List<MyTimeFrame> createTimeFrames(final MyTimeFrame timeFrame, final Calendar now) {

0 commit comments

Comments
 (0)