Skip to content

Commit

Permalink
major autodraft revision to match type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
harryprayiv committed Mar 13, 2024
1 parent a79c21e commit 2eaf455
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/ADT/Roster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ instance FromJSON Roster where
<*> v .: "SP"
<*> v .: "RP"

-- ToJSON Instances
instance ToJSON LgManager where
toJSON (LgManager status commissioner teamId leagueID currentLineup roster) =
object
[ "status" .= status
, "commissioner" .= commissioner
, "teamId" .= teamId
, "leagueID" .= leagueID
, "current_lineup" .= currentLineup
, "roster" .= roster
]

instance ToJSON CurrentLineup where
toJSON (CurrentLineup cC b1C b2C b3C ssC ofC uC spC rpC) =
object
[ "C" .= cC
, "1B" .= b1C
, "2B" .= b2C
, "3B" .= b3C
, "SS" .= ssC
, "OF" .= ofC
, "U" .= uC
, "SP" .= spC
, "RP" .= rpC
]

instance ToJSON Roster where
toJSON (Roster cR b1R b2R b3R ssR ofR uR spR rpR) =
Expand Down
39 changes: 36 additions & 3 deletions src/AutoDraft.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ addPlayerToPosition position player roster =
"utility" -> roster { R.uR = playerIdText : R.uR roster }
_ -> roster -- Default case if position does not match

createLgManager :: T.Text -> T.Text -> T.Text -> T.Text -> R.CurrentLineup -> R.Roster -> R.LgManager
createLgManager status commissioner teamId leagueID currentLineup roster =
R.LgManager status commissioner teamId leagueID currentLineup roster

-- let allRankings = [team1Rankings, team2Rankings, team3Rankings]

-- roundRobinDraft :: C.Configuration -> [[PR.PlayerRanking]] -> [[O.OfficialPlayer]] -> [R.Roster] -> Int -> IO [R.Roster]
Expand Down Expand Up @@ -141,6 +145,25 @@ addPlayerToPosition position player roster =
-- Nothing -> roster

-- bringing it all together

-- main :: IO ()
-- main = do
-- eitherR1 <- readJson "testFiles/appData/rankings/_2f70cf31d261_.json"
-- eitherR2 <- readJson "testFiles/appData/rankings/_3da9fd7edb1b_.json"
-- eitherRoster <- readJson "testFiles/appData/rosters/activePlayers.json"
-- eitherConfig <- readJson "testFiles/appData/config/config.json"

-- case (eitherR1, eitherR2, eitherRoster, eitherConfig) of
-- (Right r1, Right r2, Right roster, Right config) -> do
-- let rankings1 = PR.rankings r1
-- rankings2 = PR.rankings r2
-- op = O.people roster
-- (finalRoster1, finalRoster2) <- draftPlayers rankings1 rankings2 op config
-- writeJson "testFiles/appData/draftResults/team1Roster.json" finalRoster1
-- writeJson "testFiles/appData/draftResults/team2Roster.json" finalRoster2
-- putStrLn "Draft completed successfully."
-- _ -> putStrLn "Failed to load one or more necessary files. Check file paths and data integrity."

main :: IO ()
main = do
eitherR1 <- readJson "testFiles/appData/rankings/_2f70cf31d261_.json"
Expand All @@ -153,8 +176,18 @@ main = do
let rankings1 = PR.rankings r1
rankings2 = PR.rankings r2
op = O.people roster
teamId1 = PR.teamId r1
teamId2 = PR.teamId r2
teamId1Short = T.take 12 teamId1
teamId2Short = T.take 12 teamId2
status = C.status config -- Temporarily Assuming 'status' is accessible directly
leagueID = C.leagueID config
commissioner = C.commissioner config
(finalRoster1, finalRoster2) <- draftPlayers rankings1 rankings2 op config
writeJson "testFiles/appData/draftResults/team1Roster.json" finalRoster1
writeJson "testFiles/appData/draftResults/team2Roster.json" finalRoster2
putStrLn "Draft completed successfully."
let currentLineup = R.CurrentLineup "" "" "" "" "" [] "" [] [] -- Example placeholder; replace with actual data
let lgManager1 = createLgManager status commissioner teamId1 leagueID currentLineup finalRoster1
lgManager2 = createLgManager status commissioner teamId2 leagueID currentLineup finalRoster2
writeJson (T.unpack $ "testFiles/appData/draftResults/" <> teamId1Short <> "_draft_results.json") lgManager1
writeJson (T.unpack $ "testFiles/appData/draftResults/" <> teamId2Short <> "_draft_results.json") lgManager2
putStrLn "Draft and LgManager serialization completed successfully."
_ -> putStrLn "Failed to load one or more necessary files. Check file paths and data integrity."
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"commissioner":"436f6d6d697373696f6e6572205363726f74756d_de65ccbedd4c080939eca365a07f06f77d5a3f5854cef00d13db7f3b7be8fc08","current_lineup":{"1B":"","2B":"","3B":"","C":"","OF":[],"RP":[],"SP":[],"SS":"","U":""},"leagueID":"9d0e0f7c5930090008ce462b9daa059ec7faf85e8b62372d2ed764f8c117e6e4","roster":{"1B":["665019","458015","642133","671213","519058","664761"],"2B":["676914","621545","663538","676761","650859","624428"],"3B":["543281","605204","608324","500871","518586","578570"],"C":["641511","663886","669221","669224","572287","672515"],"OF":["571980","660766","677008","592450","672744","668804","545361","694497"],"RP":["669674","656222","700363","686973","656849","656629","622251"],"SP":["596057","669796","668984","686294","641743","663992","676702","621244","605182","641778"],"SS":["679845","680574","677587","669200","682928","622761"],"U":["596129","623912","607461","474832","443558","543543"]},"status":"I","teamId":"2f70cf31d26173571cc02a031ae7e310f24ac95a1ecabffd0d9fc5f68270ee63"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"commissioner":"436f6d6d697373696f6e6572205363726f74756d_de65ccbedd4c080939eca365a07f06f77d5a3f5854cef00d13db7f3b7be8fc08","current_lineup":{"1B":"","2B":"","3B":"","C":"","OF":[],"RP":[],"SP":[],"SS":"","U":""},"leagueID":"9d0e0f7c5930090008ce462b9daa059ec7faf85e8b62372d2ed764f8c117e6e4","roster":{"1B":["519203","669911","664774","572138","613564","456781"],"2B":["643446","600301","592273","645277","676625","676701"],"3B":["656403","681962","666198","641531","543685","683002"],"C":["641598","444489","543510","643376","642851","518735"],"OF":["671221","596103","680757","595777","686759","641933","686894","807799"],"RP":["640462","672715","547179","543507","687145","607536","656794"],"SP":["489446","672578","666168","572403","607968","448179","623167","547184","664192","594798"],"SS":["606115","669242","683011","657061","682622","677649"],"U":["457759","542303","547180","663330","608841","608385"]},"status":"I","teamId":"3da9fd7edb1b6028b732248a2e0b7f3f0cfdfa4e08c8232df2e81fc6be404eb1"}
1 change: 0 additions & 1 deletion testFiles/appData/draftResults/team1Roster.json

This file was deleted.

1 change: 0 additions & 1 deletion testFiles/appData/draftResults/team2Roster.json

This file was deleted.

0 comments on commit 2eaf455

Please sign in to comment.