-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished Data layer of Intraday and CompanyInfo
- Loading branch information
1 parent
d920370
commit 7307abf
Showing
12 changed files
with
175 additions
and
12 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
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/example/stockmarketcheck/mainFeature/data/csv/IntradayInfoParser.kt
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,56 @@ | ||
package com.example.stockmarketcheck.mainFeature.data.csv | ||
|
||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import com.example.stockmarketcheck.mainFeature.domain.model.IntradayInfo | ||
import com.opencsv.CSVReader | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.InputStream | ||
import java.io.InputStreamReader | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
import java.util.Locale | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class IntradayInfoParser | ||
@Inject | ||
constructor() : CSVParser<IntradayInfo> { | ||
@RequiresApi(Build.VERSION_CODES.O) | ||
override suspend fun parse(stream: InputStream): List<IntradayInfo> { | ||
val csvReader = CSVReader(InputStreamReader(stream)) | ||
return withContext(Dispatchers.IO) { | ||
csvReader | ||
.readAll() | ||
.drop(1) | ||
.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(), | ||
) | ||
} // 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(4).dayOfMonth | ||
} | ||
.sortedBy { | ||
it.date.hour | ||
} | ||
.also { | ||
csvReader.close() | ||
} | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
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 | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/example/stockmarketcheck/mainFeature/data/remote/dto/CompanyInfoDto.kt
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,12 @@ | ||
package com.example.stockmarketcheck.mainFeature.data.remote.dto | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
// Seria el "Response" que llama a aristidevs y es el que sera rellenado x ConverterFactoryJson | ||
data class CompanyInfoDto( | ||
@SerializedName("Symbol") val symbol: String?, | ||
@SerializedName("Description") val description: String?, | ||
@SerializedName("Name") val name: String?, | ||
@SerializedName("Country") val country: String?, | ||
@SerializedName("Industry") val industry: String?, | ||
) |
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
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/example/stockmarketcheck/mainFeature/domain/model/CompanyInfo.kt
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,9 @@ | ||
package com.example.stockmarketcheck.mainFeature.domain.model | ||
|
||
data class CompanyInfo( | ||
val symbol: String?, | ||
val description: String?, | ||
val name: String?, | ||
val country: String?, | ||
val industry: String?, | ||
) |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/example/stockmarketcheck/mainFeature/domain/model/IntradayInfo.kt
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,8 @@ | ||
package com.example.stockmarketcheck.mainFeature.domain.model | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class IntradayInfo( | ||
val date: LocalDateTime, | ||
val close: Double, | ||
) |
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