Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open FSharp.Json
- open FSharp.Data
- open System
- //On fetching data if data is [] then it is the end
- //http://api.heatmaps.tf/maps/ctf_2fort/kills?fields=["killer_class","killer_x","killer_y","killer_z","victim_x","victim_y","victim_z"]&limit=5000&offset=0
- //sniper class: 2
- //Data for kills
- type Kills =
- { map_data: MapData; fields: string list; data: float list list }
- and MapData =
- { name: string; offset_x: int; offset_y: int; scale: float; kill_count: int }
- //Return a list of kills from heatmaps.tf with limit and offset
- let FetchData map (limit:int) (page:int) =
- //Throttle requests to max 20/sec, heatmaps.tf requests max requests be 20/sec
- let event = new System.Threading.AutoResetEvent(false)
- let timer = new System.Timers.Timer(50.0)
- timer.Elapsed.Add (fun _ -> event.Set() |> ignore)
- timer.Start()
- event.WaitOne() |> ignore
- //printfn "Fetching page %i for %s" page map
- Http.RequestString ("http://api.heatmaps.tf/maps/" + map + "/kills?fields=[%22killer_class%22,%22killer_x%22,%22killer_y%22,%22killer_z%22,%22victim_x%22,%22victim_y%22,%22victim_z%22]&limit=" + string limit + "&offset=" + string (limit*page))
- //Return length between 2 points using heatmapt.tf fields formatting
- let CalculateDistance (values:float list) =
- let x = values.[1] - values.[4]
- let y = values.[2] - values.[5]
- let z = values.[3] - values.[6]
- pown x 2 + pown y 2 + pown z 2
- |> sqrt
- //Parse map data to get a list of kills from snipers
- let rec ParseData map (offset:int): float list =
- //printfn "Parsing offset %i of %s" offset map
- let data = Json.deserialize<Kills> (FetchData map 5000 offset)
- if data.data = [] || offset = 20 then
- []
- else
- data.data
- |> List.filter (fun x -> x.[0] = 2.0)
- |> List.map (fun x -> CalculateDistance x)
- |> List.append (ParseData map (offset+1))
- //Take parsed data and get useful data
- let ProcessData map =
- let data = ParseData map 0
- Console.ForegroundColor <- ConsoleColor.Yellow
- printfn "Longest kill in %A was %A" map (data |> List.max)
- [<EntryPoint>]
- let main argv =
- Console.ForegroundColor <- ConsoleColor.Blue
- ProcessData "ctf_2fort"
- System.Console.ReadKey() |> ignore
- 0
Add Comment
Please, Sign In to add comment