@ -10,10 +10,6 @@ import LeStorage
struct PadelClubView : View {
struct PadelClubView : View {
@ State private var uuid : UUID = UUID ( )
@ State private var uuid : UUID = UUID ( )
@ State private var checkingFilesAttempt : Int = 0
@ State private var checkingFiles : Bool = false
@ AppStorage ( " importingFiles " ) var importingFiles : Bool = false
@ EnvironmentObject var dataStore : DataStore
@ EnvironmentObject var dataStore : DataStore
var lastDataSource : String ? {
var lastDataSource : String ? {
@ -21,6 +17,7 @@ struct PadelClubView: View {
}
}
@ Environment ( \ . managedObjectContext ) private var viewContext
@ Environment ( \ . managedObjectContext ) private var viewContext
@ Environment ( ImportObserver . self ) private var importObserver : ImportObserver
@ FetchRequest (
@ FetchRequest (
sortDescriptors : [ ] ,
sortDescriptors : [ ] ,
@ -38,7 +35,22 @@ struct PadelClubView: View {
var body : some View {
var body : some View {
List {
List {
#if targetEnvironment ( simulator )
let monthData = dataStore . monthData . sorted ( by : \ . creationDate ) . reversed ( )
if let currentMonth = monthData . first , currentMonth . incompleteMode {
Section {
Text ( " Attention, depuis Août 2024, les données fédérales publiques des joueurs (messieurs) récupérables sont incomplètes car limité au 40.000 premiers joueurs. Le rang d'un joueur non-classé n'est donc pas calculable pour le moment, Padel Club utilisera une valeur par défaut de de 60.000. " )
Text ( " Un classement souligné comme ci-dessous indiquera que l'information provient d'un mois précédent. " )
Text ( " 10342ème " )
. background {
UnderlineView ( )
}
}
}
#if DEBUG
/*
/*
[ " 36435 " , " BOUNOUA " , " walid " , " France " , " 3311600 " , " 15,00 " , " Non " , " 2 " , " AUVERGNE RHONE-ALPES " , " 50 73 0046 " , " CHAMBERY TC " ]
[ " 36435 " , " BOUNOUA " , " walid " , " France " , " 3311600 " , " 15,00 " , " Non " , " 2 " , " AUVERGNE RHONE-ALPES " , " 50 73 0046 " , " CHAMBERY TC " ]
[ " 36435 " , " BRUL… " , " Romain " , " France " , " 2993139 " , " 15,00 " , " Non " , " 2 " , " NOUVELLE AQUITAINE " , " 59 33 0447 " , " SAINT LOUBES TC " ]
[ " 36435 " , " BRUL… " , " Romain " , " France " , " 2993139 " , " 15,00 " , " Non " , " 2 " , " NOUVELLE AQUITAINE " , " 59 33 0447 " , " SAINT LOUBES TC " ]
@ -83,7 +95,7 @@ struct PadelClubView: View {
}
}
}
}
if let mostRecentDateAvailable = SourceFileManager . shared . mostRecentDateAvailable , _lastDataSourceDate . isEarlierThan ( mostRecentDateAvailable ) , importingFiles = = false {
if let mostRecentDateAvailable = SourceFileManager . shared . mostRecentDateAvailable , _lastDataSourceDate . isEarlierThan ( mostRecentDateAvailable ) , importObserver . isImport ingFile ( ) = = false {
Section {
Section {
RowButtonView ( " Importer \( mostRecentDateAvailable . monthYearFormatted ) " ) {
RowButtonView ( " Importer \( mostRecentDateAvailable . monthYearFormatted ) " ) {
_startImporting ( )
_startImporting ( )
@ -100,7 +112,7 @@ struct PadelClubView: View {
Text ( " Padel Club va récupérer les données des mois précédents " )
Text ( " Padel Club va récupérer les données des mois précédents " )
}
}
if importingFiles {
if importObserver . isImport ingFile ( ) {
ContentUnavailableView ( " Importation en cours " , systemImage : " server.rack " , description : Text ( " Une importation des données fédérales publiques est en cours, veuillez patienter. " ) )
ContentUnavailableView ( " Importation en cours " , systemImage : " server.rack " , description : Text ( " Une importation des données fédérales publiques est en cours, veuillez patienter. " ) )
} else if ( players . isEmpty || lastDataSource = = nil ) {
} else if ( players . isEmpty || lastDataSource = = nil ) {
ContentUnavailableView {
ContentUnavailableView {
@ -116,7 +128,6 @@ struct PadelClubView: View {
}
}
}
}
let monthData = dataStore . monthData . sorted ( by : \ . creationDate ) . reversed ( )
ForEach ( monthData ) { monthData in
ForEach ( monthData ) { monthData in
Section {
Section {
LabeledContent {
LabeledContent {
@ -134,13 +145,15 @@ struct PadelClubView: View {
Text ( " Dames " )
Text ( " Dames " )
}
}
// L a b e l e d C o n t e n t {
if monthData . incompleteMode {
// i f l e t a n o n y m o u s C o u n t = m o n t h D a t a . a n o n y m o u s C o u n t {
LabeledContent {
// T e x t ( a n o n y m o u s C o u n t . f o r m a t t e d ( ) )
if let anonymousCount = monthData . anonymousCount {
// }
Text ( anonymousCount . formatted ( ) )
// } l a b e l : {
}
// T e x t ( " J o u e u r s a n o n y m e s " )
} label : {
// }
Text ( " Joueurs anonymes " )
}
}
LabeledContent {
LabeledContent {
if let maleUnrankedValue = monthData . maleUnrankedValue {
if let maleUnrankedValue = monthData . maleUnrankedValue {
@ -148,8 +161,12 @@ struct PadelClubView: View {
}
}
} label : {
} label : {
Text ( " Rang d'un non classé " )
Text ( " Rang d'un non classé " )
if monthData . incompleteMode {
Text ( " Messieurs (estimation car incomplet) " )
} else {
Text ( " Messieurs " )
Text ( " Messieurs " )
}
}
}
LabeledContent {
LabeledContent {
if let femaleUnrankedValue = monthData . femaleUnrankedValue {
if let femaleUnrankedValue = monthData . femaleUnrankedValue {
Text ( femaleUnrankedValue . formatted ( ) )
Text ( femaleUnrankedValue . formatted ( ) )
@ -170,7 +187,7 @@ struct PadelClubView: View {
FooterButtonView ( " recalculer " ) {
FooterButtonView ( " recalculer " ) {
Task {
Task {
if let monthKeyDate = URL . importDateFormatter . date ( from : monthData . monthKey ) {
if let monthKeyDate = URL . importDateFormatter . date ( from : monthData . monthKey ) {
await MonthData . calculateCurrentUnrankedValues ( mostRecentDateAvailabl e: monthKeyDate )
await MonthData . calculateCurrentUnrankedValues ( fromDat e: monthKeyDate )
}
}
}
}
}
}
@ -193,14 +210,10 @@ struct PadelClubView: View {
@ ViewBuilder
@ ViewBuilder
func _activityStatus ( ) -> some View {
func _activityStatus ( ) -> some View {
if checkingFiles || importingFiles {
if importObserver . checkingFiles || importObserver . isImport ingFile ( ) {
HStack ( spacing : 20 ) {
HStack ( spacing : 20 ) {
ProgressView ( )
ProgressView ( )
if let mostRecentDateAvailable = SourceFileManager . shared . mostRecentDateAvailable {
Text ( importObserver . currentlyImportingLabel ( ) )
if mostRecentDateAvailable > SourceFileManager . shared . lastDataSourceDate ( ) ? ? . distantPast {
Text ( " import " + mostRecentDateAvailable . monthYearFormatted )
}
}
}
}
} else if let _mostRecentDateAvailable {
} else if let _mostRecentDateAvailable {
if _mostRecentDateAvailable > _lastDataSourceDate ? ? . distantPast {
if _mostRecentDateAvailable > _lastDataSourceDate ? ? . distantPast {
@ -218,27 +231,30 @@ struct PadelClubView: View {
print ( " check internet " )
print ( " check internet " )
print ( " check files on internet " )
print ( " check files on internet " )
print ( " check if any files on internet are more recent than here " )
print ( " check if any files on internet are more recent than here " )
checkingFiles = true
importObserver . checkingFiles = true
await SourceFileManager . shared . fetchData ( )
await SourceFileManager . shared . fetchData ( )
checkingFilesAttempt += 1
importObserver . checkingFilesAttempt += 1
checkingFiles = false
importObserver . checkingFiles = false
uuid = UUID ( )
// u u i d = U U I D ( )
}
}
private func _startImporting ( ) {
private func _startImporting ( ) {
importingFiles = true
let importingDate = SourceFileManager . shared . mostRecentDateAvailable
importObserver . currentImportDate = importingDate
Task {
Task {
let lastDataSource = await FileImportManager . shared . importDataFromFFT ( )
if let importingDate {
await MainActor . run {
let lastDataSource = await FileImportManager . shared . importDataFromFFT ( importingDate : importingDate )
importingFiles = false
}
dataStore . appSettings . lastDataSource = lastDataSource
dataStore . appSettings . lastDataSource = lastDataSource
dataStore . appSettingsStorage . write ( )
dataStore . appSettingsStorage . write ( )
if let lastDataSource , let mostRecentDate = URL . importDateFormatter . date ( from : lastDataSource ) {
if let lastDataSource , let mostRecentDate = URL . importDateFormatter . date ( from : lastDataSource ) {
await MonthData . calculateCurrentUnrankedValues ( mostRecentDateAvailabl e: mostRecentDate )
await MonthData . calculateCurrentUnrankedValues ( fromDat e: mostRecentDate )
}
}
viewContext . refreshAllObjects ( )
viewContext . refreshAllObjects ( )
}
}
await MainActor . run {
importObserver . currentImportDate = nil
}
}
}
}
private func _downloadPreviousDate ( ) async {
private func _downloadPreviousDate ( ) async {