-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from rladstaetter/12-extract-time-instant-inf…
…ormation-from-log-files 12 extract time instant information from log files
- Loading branch information
Showing
49 changed files
with
642 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 19 additions & 10 deletions
29
app/src/main/scala/app/logorrr/model/LogEntryInstantFormat.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
package app.logorrr.model | ||
|
||
import app.logorrr.views.SimpleRange | ||
import app.logorrr.util.CanLog | ||
import app.logorrr.views.settings.timer.SimpleRange | ||
import pureconfig.generic.semiauto.{deriveReader, deriveWriter} | ||
|
||
import java.time.format.DateTimeFormatter | ||
import java.time.{Instant, LocalDateTime, ZoneId, ZoneOffset} | ||
import scala.util.Try | ||
import scala.util.{Failure, Success, Try} | ||
|
||
object LogEntryInstantFormat { | ||
object LogEntryInstantFormat extends CanLog { | ||
|
||
val DefaultPattern = "yyyy-MM-dd HH:mm:ss.SSS" | ||
val DefaultPattern = "yyyy-MM-dd HH:mm:ss.nnnnnnnnn" | ||
/** just my preferred time format */ | ||
val Default = LogEntryInstantFormat(SimpleRange(1, 24), DefaultPattern) | ||
|
||
implicit lazy val reader = deriveReader[LogEntryInstantFormat] | ||
implicit lazy val writer = deriveWriter[LogEntryInstantFormat] | ||
|
||
def parseInstant(line: String, entrySetting: LogEntryInstantFormat): Option[Instant] = | ||
if (line.length >= entrySetting.dateTimeRange.end) { | ||
if (line.length >= entrySetting.endCol) { | ||
val dateTimeAsString = line.substring(entrySetting.startCol, entrySetting.endCol) | ||
Try { | ||
val dateTimeAsString = line.substring(entrySetting.dateTimeRange.start, entrySetting.dateTimeRange.end) | ||
val dtf: DateTimeFormatter = entrySetting.dateTimeFormatter | ||
LocalDateTime.parse(dateTimeAsString, dtf).toInstant(ZoneOffset.of(entrySetting.zoneOffset)) | ||
}.toOption | ||
} else None | ||
} match { | ||
case Success(value) => Option(value) | ||
case Failure(_) => | ||
logTrace(s"Could not parse '$dateTimeAsString' at pos (${entrySetting.startCol}/${entrySetting.endCol}) with pattern '$${entrySetting.dateTimePattern}'") | ||
None | ||
} | ||
} else { | ||
None | ||
} | ||
|
||
|
||
} | ||
|
||
case class LogEntryInstantFormat(dateTimeRange: SimpleRange | ||
case class LogEntryInstantFormat(range: SimpleRange | ||
, dateTimePattern: String | ||
, zoneOffset: String = "+1") { | ||
|
||
val startCol = range.start | ||
val endCol = range.end | ||
val dateTimeFormatter = DateTimeFormatter.ofPattern(dateTimePattern).withZone(ZoneId.of(zoneOffset)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.logorrr.util | ||
|
||
import javafx.geometry.Insets | ||
import javafx.scene.control.Label | ||
import javafx.scene.layout.{Background, BackgroundFill} | ||
import javafx.scene.paint.Color | ||
|
||
object LabelUtil { | ||
|
||
def setStyle(label: Label, textFill: Color, padding: Insets, backgroundColor: Color): Unit = { | ||
label.setTextFill(textFill) | ||
label.setPadding(padding) | ||
label.setBackground(new Background(new BackgroundFill(backgroundColor, null, null))) | ||
} | ||
|
||
def resetStyle(label: Label): Unit = { | ||
label.setBackground(null) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package app.logorrr.util | ||
|
||
import java.nio.file.Paths | ||
|
||
object LogFileUtil { | ||
|
||
/** compute file name from a LogFilePath */ | ||
def logFileName(pathAsString: String): String = | ||
Paths.get(pathAsString).getFileName.toString | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.