Skip to content

Commit

Permalink
test are passing locally, lets see if they pass in the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonelZalegas committed Jul 24, 2024
1 parent 0d797fc commit 5ceb72c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.io.InputStreamReader
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException
import java.util.Locale
import javax.inject.Inject
import javax.inject.Singleton
Expand All @@ -26,10 +27,15 @@ class IntradayInfoParser
.mapNotNull { line ->
val timestamp = line.getOrNull(0) ?: return@mapNotNull null
val close = line.getOrNull(4) ?: return@mapNotNull null
IntradayInfo(
date = convertToLocalDateTime(timestamp),
close = close.toDouble(),
)
val date = convertToLocalDateTime(timestamp) ?: return@mapNotNull null
try {
IntradayInfo(
date = date,
close = close.toDouble(),
)
} catch (e: NumberFormatException) {
null // Return null if close price is not a valid double
}
} // Aca ya tenemos la lista de IntradayInfo pero a esto filtramos y Guardamos solo
.filter { // los IntradayInfo con campo date = a la fecha de ayer de nuetra maquina
it.date.dayOfMonth == LocalDate.now().minusDays(1).dayOfMonth
Expand All @@ -43,10 +49,13 @@ class IntradayInfoParser
}
}

private fun convertToLocalDateTime(timestamp: String): LocalDateTime {
val pattern = "yyyy-MM-dd HH:mm:ss"
val formatter = DateTimeFormatter.ofPattern(pattern, Locale.getDefault())
val localDateTime = LocalDateTime.parse(timestamp, formatter)
return localDateTime
private fun convertToLocalDateTime(timestamp: String): LocalDateTime? {
return try {
val pattern = "yyyy-MM-dd HH:mm:ss"
val formatter = DateTimeFormatter.ofPattern(pattern, Locale.getDefault())
LocalDateTime.parse(timestamp, formatter)
} catch (e: DateTimeParseException) {
null // Return null if parsing fails
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.stockmarketcheck.mainFeature.data.csv
import com.example.stockmarketcheck.mainFeature.domain.model.IntradayInfo
import com.opencsv.CSVReader
import io.mockk.every
import io.mockk.mockkConstructor
import io.mockk.mockkStatic
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -56,6 +57,7 @@ class IntradayInfoParserTest {

// Mock the CSVReader
mockkStatic("com.opencsv.CSVReaderBuilder")
mockkConstructor(CSVReader::class)
every { anyConstructed<CSVReader>().readAll() } returns
listOf(
arrayOf("timestamp", "open", "high", "low", "close", "volume"),
Expand Down Expand Up @@ -93,6 +95,7 @@ class IntradayInfoParserTest {

// Mock the CSVReader
mockkStatic("com.opencsv.CSVReaderBuilder")
mockkConstructor(CSVReader::class)
every { anyConstructed<CSVReader>().readAll() } returns
listOf(
arrayOf("timestamp", "open", "high", "low", "close", "volume"),
Expand Down

0 comments on commit 5ceb72c

Please sign in to comment.