How to use FormatDuration method of types Package

Best Testkube code snippet using types.FormatDuration

web.go

Source:web.go Github

copy

Full Screen

1package main2//https://azure.microsoft.com/en-gb/blog/running-go-applications-on-azure-app-service/3import (4 "fmt"5 "io/ioutil"6 "net/http"7 "os"8 "strconv"9 "strings"10 "time"11 "github.com/dotabuff/manta"12 "github.com/dotabuff/manta/dota"13)14func formatDuration(d time.Duration) string {15 return time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC).Add(d).Truncate(time.Second).Format("15:04:05.999999999")16}17func v1ParseLog(w http.ResponseWriter, r *http.Request) {18 switch r.Method {19 case "POST":20 var demoFile []byte21 if strings.Contains(r.Header.Get("Content-Type"), "multipart/form-data;") {22 form, _ := r.MultipartReader(); 23 part, _ := form.NextPart(); 24 demoFile, _ = ioutil.ReadAll(part); 25 } else {26 demoFile, _ = ioutil.ReadAll(r.Body);27 }28 29 var gameTime time.Duration30 var preGameStartTime time.Duration31 var gameStartTime time.Duration32 var gameEndTime time.Duration33 var iPlayerResources map[int]time.Duration34 iPlayerResources = make(map[int]time.Duration)35 36 var iTeamData map[int]time.Duration37 iTeamData = make(map[int]time.Duration)38 39 var iHeroUnits map[int]time.Duration40 iHeroUnits = make(map[int]time.Duration)41 42 var owners map[uint32]int3243 owners = make(map[uint32]int32)44 45 var heroes map[int]int3246 heroes = make(map[int]int32)47 48 49 p, _ := manta.NewParser(demoFile)50 51 p.OnPacketEntity(func(pe *manta.PacketEntity, pet manta.EntityEventType) error {52 53 if pe.ClassName == "CDOTAGamerulesProxy" {54 if v, ok := pe.FetchFloat32("CDOTAGamerules.m_fGameTime"); ok {55 gameTime = time.Duration(v) * time.Second 56 }57 if v, ok := pe.FetchFloat32("CDOTAGamerules.m_flPreGameStartTime"); ok {58 preGameStartTime = time.Duration(v) * time.Second 59 }60 if v, ok := pe.FetchFloat32("CDOTAGamerules.m_flGameStartTime"); ok {61 gameStartTime = time.Duration(v) * time.Second 62 }63 if v, ok := pe.FetchFloat32("CDOTAGamerules.m_flGameEndTime"); ok {64 gameEndTime = time.Duration(v) * time.Second 65 }66 }67 68 if pe.ClassName == "CDOTA_PlayerResource" {69 for i := 0; i < 10; i++ {70 lastInterval := iPlayerResources[i]71 if(gameTime.Seconds() > (lastInterval.Seconds() + 10)) {72 iPlayerResources[i] = gameTime 73 74 heroID, _ := pe.FetchInt32("m_vecPlayerTeamData.000" + strconv.Itoa(i) + ".m_nSelectedHeroID")75 if(heroID > 0) {76 heroes[i] = heroID77 78 level, _ := pe.FetchInt32("m_vecPlayerTeamData.000" + strconv.Itoa(i) + ".m_iLevel")79 assists, _ := pe.FetchInt32("m_vecPlayerTeamData.000" + strconv.Itoa(i) + ".m_iAssists")80 deaths, _ := pe.FetchInt32("m_vecPlayerTeamData.000" + strconv.Itoa(i) + ".m_iDeaths")81 kills, _ := pe.FetchInt32("m_vecPlayerTeamData.000" + strconv.Itoa(i) + ".m_iKills")82 83 fmt.Fprintf(w, "{\"type\":2,\"time\":\"%s\",\"hero\":%d,\"level\":%d,\"kills\":%d,\"deaths\":%d,\"assists\":%d},", formatDuration(gameTime), heroID,level, kills, deaths, assists)84 }85 }86 }87 }88 if pe.ClassName == "CDOTA_DataDire" || pe.ClassName == "CDOTA_DataRadiant"{89 for i := 0; i < 5; i++ {90 var playerID = i91 if(pe.ClassName == "CDOTA_DataDire") {92 playerID += 593 }94 95 lastInterval := iTeamData[int(playerID)]96 if(gameTime.Seconds() > (lastInterval.Seconds() + 5)) {97 iTeamData[int(playerID)] = gameTime 98 99 if heroID, ok := heroes[int(playerID)]; ok {100 101 healing, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_fHealing")102 stuns, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_fStuns")103 buybackCooldown, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_flBuybackCooldownTime")104 creepGold, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iCreepKillGold")105 denies, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iDenyCount")106 heroGold, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iHeroKillGold")107 incomeGold, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iIncomeGold")108 lastHits, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iLastHitCount")109 missCount, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iMissCount")110 nearbyCreepCount, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iNearbyCreepDeathCount")111 reliableGold, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iReliableGold")112 unreliableGold, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iUnreliableGold")113 sharedGold, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iSharedGold")114 gold, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iTotalEarnedGold")115 xp, _ := pe.FetchInt32("m_vecDataTeam.000" + strconv.Itoa(i) + ".m_iTotalEarnedXP")116 117 fmt.Fprintf(w, "{\"type\":3,\"time\":\"%s\",\"hero\":%d,\"healing\":%d,\"stuns\":%d,\"buyback\":%d,\"lasthits\":%d,\"denies\":%d,\"misses\":%d,\"nearby_creeps\":%d,\"gold_creeps\":%d,\"gold_heroes\":%d,\"gold_income\":%d,\"gold_reliable\":%d,\"gold_unreliable\":%d,\"gold_shared\":%d,\"gold\":%d,\"xp\":%d},", formatDuration(gameTime), heroID, healing,stuns,buybackCooldown,lastHits,denies,missCount,nearbyCreepCount,creepGold,heroGold,incomeGold,reliableGold,unreliableGold,sharedGold,gold,xp)118 }119 }120 }121 }122 123 if strings.HasPrefix(pe.ClassName,"CDOTA_Unit_Hero") {124 playerID, _ := pe.FetchInt32("m_iPlayerID")125 ownerID, _ := pe.Fetch("m_hOwnerEntity")126 127 lastInterval := iHeroUnits[int(playerID)]128 if(gameTime.Seconds() > (lastInterval.Seconds() + 0)) {129 iHeroUnits[int(playerID)] = gameTime 130 131 if heroID, ok := heroes[int(playerID)]; ok {132 owners[ownerID.(uint32)] = heroID133 134 x, _ := pe.Fetch("CBodyComponentBaseAnimatingOverlay.m_cellX")135 y, _ := pe.Fetch("CBodyComponentBaseAnimatingOverlay.m_cellY")136 137 fmt.Fprintf(w, "{\"type\":4,\"time\":\"%s\",\"hero\":%d,\"x\":%d,\"y\":%d},", formatDuration(gameTime), heroID, x, y) 138 }139 }140 }141 142 if pe.ClassName == "CDOTA_NPC_Observer_Ward" && pet == manta.EntityEventType_Create {143 x, _ := pe.Fetch("CBodyComponentBaseAnimatingOverlay.m_cellX")144 y, _ := pe.Fetch("CBodyComponentBaseAnimatingOverlay.m_cellY")145 ownerID, _ := pe.Fetch("m_hOwnerEntity")146 heroID := owners[ownerID.(uint32)]147 148 fmt.Fprintf(w, "{\"type\":5,\"time\":\"%s\",\"x\":%d,\"y\":%d,\"hero\":%d},", formatDuration(gameTime), x, y, heroID)149 }150 151 if pe.ClassName == "CDOTA_NPC_Observer_Ward_TrueSight" && pet == manta.EntityEventType_Create {152 x, _ := pe.Fetch("CBodyComponentBaseAnimatingOverlay.m_cellX")153 y, _ := pe.Fetch("CBodyComponentBaseAnimatingOverlay.m_cellY")154 ownerID, _ := pe.Fetch("m_hOwnerEntity")155 heroID := owners[ownerID.(uint32)]156 157 fmt.Fprintf(w, "{\"type\":6,\"time\":\"%s\",\"x\":%d,\"y\":%d,\"hero\":%d},", formatDuration(gameTime), x, y, heroID)158 } 159 160 return nil161 })162 p.Callbacks.OnCUserMessageSayText2(func(m *dota.CUserMessageSayText2) error {163 fmt.Fprintf(w, "{\"type\":7,\"time\":\"%s\",\"player\":\"%s\",\"said\":\"%s\"},", formatDuration(gameTime), m.GetParam1(), m.GetParam2())164 return nil165 })166 167 p.Callbacks.OnCDOTAUserMsg_ChatEvent(func(e *dota.CDOTAUserMsg_ChatEvent) error {168 169 t := e.GetType()170 switch dota.DOTA_CHAT_MESSAGE (t) {171 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_HERO_KILL:172 // covered by combat log173 174 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_HERO_DENY:175 // covered by combat log176 177 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_BARRACKS_KILL:178 //They go in incremental powers of 2, starting by the Dire side to the Dire Side, Bottom to Top, Melee to Ranged179 //ex: Bottom Melee Dire Rax = 1 and Top Ranged Radiant Rax = 2048.180 fmt.Fprintf(w, "{\"type\":8,\"time\":\"%s\",\"barracks\":%d,\"player\":%d},", formatDuration(gameTime), e.GetValue(), e.GetPlayerid_1())181 182 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_TOWER_KILL:183 //player1 = slot of player who killed tower (-1 if nonplayer)184 //value (2/3 radiant/dire killed tower, recently 0/1?)185 fmt.Fprintf(w, "{\"type\":9,\"time\":\"%s\",\"tower\":%d,\"player\":%d},", formatDuration(gameTime), e.GetValue(), e.GetPlayerid_1())186 187 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_TOWER_DENY:188 fmt.Fprintf(w, "{\"type\":10,\"time\":\"%s\",\"tower\":%d,\"player\":%d},", formatDuration(gameTime), e.GetValue(), e.GetPlayerid_1())189 190 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_EFFIGY_KILL:191 fmt.Fprintf(w, "{\"type\":11,\"time\":\"%s\",\"player\":%d},", formatDuration(gameTime), e.GetPlayerid_1())192 193 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_FIRSTBLOOD:194 fmt.Fprintf(w, "{\"type\":12,\"time\":\"%s\",\"player\":%d},", formatDuration(gameTime), e.GetPlayerid_1())195 196 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_STREAK_KILL:197 // covered by combat log198 199 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_BUYBACK:200 // covered by combat log201 202 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_ROSHAN_KILL:203 //player1 = team that killed roshan? (2/3)204 fmt.Fprintf(w, "{\"type\":13,\"time\":\"%s\",\"team\":%d,\"value\":%d},", formatDuration(gameTime), e.GetPlayerid_1(), e.GetValue())205 206 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_AEGIS:207 //player1 = slot who picked up/denied/stole aegis208 fmt.Fprintf(w, "{\"type\":14,\"time\":\"%s\",\"player\":%d},", formatDuration(gameTime), e.GetPlayerid_1())209 210 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_AEGIS_STOLEN:211 fmt.Fprintf(w, "{\"type\":15,\"time\":\"%s\",\"player\":%d},", formatDuration(gameTime), e.GetPlayerid_1())212 213 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_DENIED_AEGIS:214 fmt.Fprintf(w, "{\"type\":16,\"time\":\"%s\",\"player\":%d},", formatDuration(gameTime), e.GetPlayerid_1())215 216 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_COURIER_LOST:217 //player1 = team that lost courier (2/3)218 fmt.Fprintf(w, "{\"type\":17,\"time\":\"%s\",\"team\":%d},", formatDuration(gameTime), e.GetPlayerid_1())219 220 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_COURIER_RESPAWNED:221 fmt.Fprintf(w, "{\"type\":18,\"time\":\"%s\",\"team\":%d},", formatDuration(gameTime), e.GetPlayerid_1())222 223 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_GLYPH_USED:224 // team that used glyph (2/3, or 0/1) ?225 fmt.Fprintf(w, "{\"type\":19,\"time\":\"%s\",\"team\":%d},", formatDuration(gameTime), e.GetPlayerid_1())226 227 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_ITEM_PURCHASE:228 // Not usefull dose not include all PURCHASES229 230 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_RUNE_PICKUP:231 fmt.Fprintf(w, "{\"type\":20,\"time\":\"%s\",\"player\":%d,\"rune\":%d},", formatDuration(gameTime), e.GetPlayerid_1(), e.GetValue())232 //"0": "Double Damage", "1": "Haste", "2": "Illusion", "3": "Invisibility", "4": "Regeneration", "4": "Bounty"233 234 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_RUNE_BOTTLE:235 fmt.Fprintf(w, "{\"type\":21,\"time\":\"%s\",\"player\":%d,\"rune\":%d},", formatDuration(gameTime), e.GetPlayerid_1(), e.GetValue())236 //"0": "Double Damage", "1": "Haste", "2": "Illusion", "3": "Invisibility", "4": "Regeneration", "4": "Bounty"237 238 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_SUPER_CREEPS:239 fmt.Fprintf(w, "{\"type\":22,\"time\":\"%s\",\"team\":%d},", formatDuration(gameTime), e.GetPlayerid_1())240 241 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_CONNECT:242 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_DISCONNECT:243 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_RECONNECT:244 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_PLAYER_LEFT:245 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_SAFE_TO_LEAVE:246 // Is this needed?247 248 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_PAUSED:249 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_UNPAUSED:250 // Maybe at some point?251 252 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_INTHEBAG:253 fmt.Fprintf(w, "{\"type\":23,\"time\":\"%s\",\"player\":%d},", formatDuration(gameTime), e.GetPlayerid_1())254 255 case dota.DOTA_CHAT_MESSAGE_CHAT_MESSAGE_TAUNT:256 // Is this needed?257 }258 259 return nil260 })261 262 p.Callbacks.OnCMsgDOTACombatLogEntry(func(m *dota.CMsgDOTACombatLogEntry) error {263 264 t := m.GetType()265 switch dota.DOTA_COMBATLOG_TYPES(t) {266 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_DAMAGE:267 iat := m.GetIsAttackerIllusion()268 iah := m.GetIsAttackerHero()269 iti := m.GetIsTargetIllusion()270 ith := m.GetIsTargetHero()271 ivr := m.GetIsVisibleRadiant()272 ivd := m.GetIsVisibleDire()273 itb:= m.GetIsTargetBuilding()274 275 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))276 targetSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetSourceName()))277 attacker, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetAttackerName()))278 damageSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetDamageSourceName())) 279 inflictor, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetInflictorName()))280 value := m.GetValue()281 282 fmt.Fprintf(w, "{\"type\":24,\"time\":\"%s\",\"iat\":%t,\"iah\":%t,\"iti\":%t,\"ith\":%t,\"ivr\":%t,\"ivd\":%t,\"itb\":%t,\"attacker\":\"%s\",\"target\":\"%s\",\"target_source\":\"%s\",\"damage_source\":\"%s\",\"inflictor\":\"%s\",\"value\":%d},", formatDuration(gameTime), iat, iah,iti,ith,ivr,ivd,itb,attacker,target,targetSource,damageSource,inflictor,value)283 284 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_HEAL:285 iat := m.GetIsAttackerIllusion()286 iah := m.GetIsAttackerHero()287 iti := m.GetIsTargetIllusion()288 ith := m.GetIsTargetHero()289 ivr := m.GetIsVisibleRadiant()290 ivd := m.GetIsVisibleDire()291 itb := m.GetIsTargetBuilding()292 293 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))294 targetSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetSourceName()))295 attacker, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetAttackerName()))296 damageSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetDamageSourceName()))297 inflictor, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetInflictorName()))298 299 value := m.GetValue()300 fmt.Fprintf(w, "{\"type\":25,\"time\":\"%s\",\"iat\":%t,\"iah\":%t,\"iti\":%t,\"ith\":%t,\"ivr\":%t,\"ivd\":%t,\"itb\":%t,\"attacker\":\"%s\",\"target\":\"%s\",\"target_source\":\"%s\",\"damage_source\":\"%s\",\"inflictor\":\"%s\",\"value\":%d},", formatDuration(gameTime), iat, iah,iti,ith,ivr,ivd,itb,attacker,target,targetSource,damageSource,inflictor,value)301 302 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_DEATH:303 iat := m.GetIsAttackerIllusion()304 iah := m.GetIsAttackerHero()305 iti := m.GetIsTargetIllusion()306 ith := m.GetIsTargetHero()307 ivr := m.GetIsVisibleRadiant()308 ivd := m.GetIsVisibleDire()309 itb := m.GetIsTargetBuilding()310 311 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))312 targetSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetSourceName()))313 attacker, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetAttackerName()))314 damageSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetDamageSourceName()))315 316 fmt.Fprintf(w, "{\"type\":26,\"time\":\"%s\",\"iat\":%t,\"iah\":%t,\"iti\":%t,\"ith\":%t,\"ivr\":%t,\"ivd\":%t,\"itb\":%t,\"attacker\":\"%s\",\"target\":\"%s\",\"target_source\":\"%s\",\"damage_source\":\"%s\"},", formatDuration(gameTime), iat, iah,iti,ith,ivr,ivd,itb,attacker,target,targetSource,damageSource)317 318 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_ABILITY:319 iat := m.GetIsAttackerIllusion()320 iah := m.GetIsAttackerHero()321 ivr := m.GetIsVisibleRadiant()322 ivd := m.GetIsVisibleDire()323 324 attacker, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetAttackerName()))325 inflictor, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetInflictorName()))326 level := m.GetAbilityLevel()327 328 fmt.Fprintf(w, "{\"type\":27,\"time\":\"%s\",\"iat\":%t,\"iah\":%t,\"ivr\":%t,\"ivd\":%t,\"attacker\":\"%s\",\"inflictor\":\"%s\",\"ability_level\":%d},", formatDuration(gameTime), iat, iah,ivr,ivd,attacker,inflictor,level)329 330 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_ITEM:331 attacker, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetAttackerName()))332 inflictor, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetInflictorName()))333 level := m.GetAbilityLevel()334 335 fmt.Fprintf(w, "{\"type\":28,\"time\":\"%s\",\"player\":\"%s\",\"item\":\"%s\",\"level\":%d},", formatDuration(gameTime), attacker, inflictor, level)336 337 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_PURCHASE:338 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))339 item, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetValue()))340 341 fmt.Fprintf(w, "{\"type\":29,\"time\":\"%s\",\"player\":\"%s\",\"item\":\"%s\"},", formatDuration(gameTime), target, item)342 343 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_BUYBACK:344 source, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetValue()))345 346 fmt.Fprintf(w, "{\"type\":30,\"time\":\"%s\",\"player\":\"%s\"},", formatDuration(gameTime), source)347 348 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_GOLD:349 amount := m.GetValue()350 351 reason := m.GetGoldReason() 352 // "0": "Other", "1":"Death", "2":"Buyback", "5": "Abandon", "6": "Sell", "11":"Structure", "12":"Hero", "13":"Creep", "14": "Roshan", "15":"Courier"353 354 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))355 targetSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetSourceName()))356 357 fmt.Fprintf(w, "{\"type\":31,\"time\":\"%s\",\"target\":\"%s\",\"targetsource\":\"%s\",\"reason\":%d,\"amount\":%d},", formatDuration(gameTime), target, targetSource, reason, amount)358 359 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_XP:360 amount := m.GetValue()361 reason := m.GetXpReason() 362 //"0": "Other", "1": "Hero", "2": "Creep", "3": "Roshan"363 364 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))365 366 fmt.Fprintf(w, "{\"type\":32,\"time\":\"%s\",\"target\":\"%s\",\"reason\":%d,\"amount\":%d},", formatDuration(gameTime), target, reason, amount)367 368 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_TEAM_BUILDING_KILL:369 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))370 371 value := m.GetValue()372 373 fmt.Fprintf(w, "{\"type\":33,\"time\":\"%s\",\"target\":\"%s\",\"value\":%d},", formatDuration(gameTime), target, value)374 375 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_NEUTRAL_CAMP_STACK:376 // Not used?377 378 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_PICKUP_RUNE:379 // use Chat Event380 381 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_FIRST_BLOOD:382 // use Chat Event383 384 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_PLAYERSTATS: 385 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_GAME_STATE:386 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_LOCATION:387 // Useless...388 389 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_MULTIKILL:390 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))391 targetSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetSourceName()))392 attacker, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetAttackerName()))393 394 value := m.GetValue()395 //"2": "Double Kill", "3": "Triple Kill", "4": "Ultra Kill", "5": "Rampage"396 397 fmt.Fprintf(w, "{\"type\":34,\"time\":\"%s\",\"attacker\":\"%s\",\"target\":\"%s\",\"target_source\":\"%s\",\"value\":%d},", 398 formatDuration(gameTime), 399 attacker,400 target,401 targetSource,402 value)403 404 case dota.DOTA_COMBATLOG_TYPES_DOTA_COMBATLOG_KILLSTREAK:405 target, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetName()))406 targetSource, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetTargetSourceName()))407 attacker, _ := p.LookupStringByIndex("CombatLogNames", int32(m.GetAttackerName()))408 value := m.GetValue()409 //"3": "Killing Spree", "4": "Dominating","5": "Mega Kill", "6": "Unstoppable", "7": "Wicked Sick", "8": "Monster Kill", "9": "Godlike", "10": "Beyond Godlike"410 411 fmt.Fprintf(w, "{\"type\":35,\"time\":\"%s\",\"attacker\":\"%s\",\"target\":\"%s\",\"target_source\":\"%s\",\"value\":%d},", 412 formatDuration(gameTime), 413 attacker,414 target,415 targetSource,416 value)417 }418 419 return nil420 })421 422 start := time.Now().UTC()423 fmt.Fprintf(w, "[{\"type\":0,\"version\":2,\"date\":\"%s\"},", start.Format(time.RFC1123Z))424 425 p.Start() 426 427 elapsed := time.Since(start)428 fmt.Fprintf(w, "{\"type\":1,\"elapsed\":\"%s\",\"pregame_start\":\"%s\",\"game_start\":\"%s\",\"game_end\":\"%s\"}]", formatDuration(elapsed), formatDuration(preGameStartTime),formatDuration(gameStartTime),formatDuration(gameEndTime))429 430 default:431 http.Error(w, "Post the replay file you wish to parse.", http.StatusMethodNotAllowed)432 return433 }434}435func everythingElse(w http.ResponseWriter, r *http.Request) {436 http.Error(w, "Welcome to Mango, please post a replay to '/v1/parse' to get started.", http.StatusNotFound)437 return438}439func main() {440 http.HandleFunc("/", everythingElse)441 http.HandleFunc("/v1/parse", v1ParseLog)442 port := "3001"443 if os.Getenv("HTTP_PLATFORM_PORT") != "" {444 port = os.Getenv("HTTP_PLATFORM_PORT")445 }446 http.ListenAndServe(":"+port, nil)447}...

Full Screen

Full Screen

watch.go

Source:watch.go Github

copy

Full Screen

...64 availableBees := GetAvailableMachines()65 out += fmt.Sprintf(fmtStr, "Machines:", FormatMachines(*machines, true)+66 " (currently available: "+FormatMachines(availableBees, true)+")")67 out += fmt.Sprintf(fmtStr, "Created:", run.CreatedDate.In(time.Local).Format(time.RFC1123)+68 " ("+util.FormatDuration(time.Since(run.CreatedDate))+" ago)")69 if run.Status != "PENDING" {70 if !run.StartedDate.IsZero() {71 out += fmt.Sprintf(fmtStr, "Started:", run.StartedDate.In(time.Local).Format(time.RFC1123)+72 " ("+util.FormatDuration(time.Since(run.StartedDate))+" ago)")73 }74 }75 if run.Finished {76 if !run.CompletedDate.IsZero() {77 out += fmt.Sprintf(fmtStr, "Finished:", run.CompletedDate.In(time.Local).Format(time.RFC1123)+78 " ("+util.FormatDuration(time.Since(run.CompletedDate))+" ago)")79 }80 out += fmt.Sprintf(fmtStr, "Duration:", util.FormatDuration(run.CompletedDate.Sub(run.StartedDate)))81 }82 if run.Status == "RUNNING" {83 out += fmt.Sprintf(fmtStr, "Duration:", util.FormatDuration(time.Since(run.StartedDate)))84 }85 subJobs := GetSubJobs(runID)86 for _, sj := range subJobs {87 allNodes[sj.NodeName].Status = strings.ToLower(sj.Status)88 allNodes[sj.NodeName].OutputStatus = strings.ReplaceAll(strings.ToLower(sj.OutputsStatus), "_", " ")89 if sj.Finished {90 allNodes[sj.NodeName].Duration = sj.FinishedDate.Sub(sj.StartedDate).Round(time.Second)91 } else {92 allNodes[sj.NodeName].Duration = time.Since(sj.StartedDate).Round(time.Second)93 }94 }95 trees := PrintTrees(roots, &allNodes, showParameters, true)96 out += "\n" + trees97 _, _ = fmt.Fprintln(writer, out)98 _ = writer.Flush()99 if timestampOnly {100 return101 }102 if run.Status == "COMPLETED" || run.Status == "STOPPED" || run.Status == "FAILED" {103 if downloadPath == "" {104 downloadPath = run.SpaceName105 if run.ProjectName != "" {106 downloadPath += "/" + run.ProjectName107 }108 downloadPath += "/" + run.WorkflowName109 }110 if downloadAllNodes {111 // DownloadRunOutputs downloads all outputs if no nodes were specified112 output.DownloadRunOutput(run, nil, nil, downloadPath)113 } else if len(nodesToDownload) > 0 {114 output.DownloadRunOutput(run, nodesToDownload, nil, downloadPath)115 }116 mutex.Unlock()117 return118 }119 mutex.Unlock()120 }121}122func PrintTrees(roots []*types.TreeNode, allNodes *map[string]*types.TreeNode, showParameters bool, table bool) string {123 trees := ""124 for _, root := range roots {125 tree := printTree(root, nil, allNodes, showParameters)126 for _, node := range *allNodes {127 node.Printed = false128 }129 if !table {130 trees += tree131 continue132 }133 writerBuffer := new(bytes.Buffer)134 w := tabwriter.NewWriter(writerBuffer, 0, 0, 2, ' ', 0)135 _, _ = fmt.Fprintf(w, "\tNODE\t STATUS\t DURATION\t OUTPUT\n")136 treeSplit := strings.Split(tree, "\n")137 for _, line := range treeSplit {138 if line != "" {139 if match, _ := regexp.MatchString(`\([-a-z0-9]+-[0-9]+\)`, line); match {140 lineSplit := strings.Split(line, "(")141 nodeName := strings.Trim(lineSplit[1], ")")142 node := (*allNodes)[nodeName]143 _, _ = fmt.Fprintf(w, "\t"+line+"\t"+node.Status+"\t"+144 util.FormatDuration(node.Duration)+"\t"+node.OutputStatus+"\n")145 } else {146 _, _ = fmt.Fprintf(w, "\t"+line+"\t\t\t\n")147 }148 }149 }150 _ = w.Flush()151 trees += writerBuffer.String()152 }153 return trees154}155func printTree(node *types.TreeNode, branch *treeprint.Tree, allNodes *map[string]*types.TreeNode, showParameters bool) string {156 prefixSymbol := ""157 switch node.Status {158 case "pending":...

Full Screen

Full Screen

output.go

Source:output.go Github

copy

Full Screen

1package lib2import (3 "fmt"4 "sort"5 "time"6 "alexi.ch/aoc2021/lib/types"7)8func AnsiBold(input string) string {9 return fmt.Sprintf("\033[31;1;4m%v\033[0m", input)10}11func AnsiRed(input string) string {12 return fmt.Sprintf("\u001b[31m%v\u001b[0m", input)13}14func AnsiYellow(input string) string {15 return fmt.Sprintf("\u001b[33m%v\u001b[0m", input)16}17func AnsiGreen(input string) string {18 return fmt.Sprintf("\u001b[32m%v\u001b[0m", input)19}20func Highlight(input string) string {21 return fmt.Sprintf("\033[1;4m%v\033[0m", input)22}23func OutputTitle(input string) {24 outStr := fmt.Sprintf("%v", input)25 fmt.Printf("\033[1;4m%v\033[0m\n\n", outStr)26}27func OutputSolution(nr int, duration time.Duration, solution string) {28 fmt.Printf("Solution %v: %v\n", nr, Highlight(solution))29 fmt.Printf("Took: %v ms\n\n", float64(duration.Nanoseconds())/1000.0/1000.0)30}31func MeasureTime(f func()) time.Duration {32 start := time.Now()33 f()34 end := time.Since(start)35 return end36}37func formatDuration(d time.Duration) string {38 if d > time.Second {39 return AnsiRed(fmt.Sprint(d))40 }41 if d > time.Millisecond*800 {42 return AnsiYellow(fmt.Sprint(d))43 }44 return AnsiGreen(fmt.Sprint(d))45}46func OutputResultList(list []types.AoCResult, total time.Duration) {47 fmt.Printf(48 "%-6s|%-35s|%15s|%15s|%15s\n",49 "Nr.",50 "Title",51 "Time Part 1",52 "Time Part 2",53 "Total time",54 )55 fmt.Print(56 "------|-----------------------------------|---------------|---------------|---------------\n",57 )58 var total1 time.Duration = 059 var total2 time.Duration = 060 var runTotal time.Duration = 061 sort.Slice(list, func(i, j int) bool {62 return list[i].Key < list[j].Key63 })64 for _, line := range list {65 total1 += line.TimeSolution166 total2 += line.TimeSolution267 runTotal += line.TimeSolution1 + line.TimeSolution268 name := line.Problem.GetName()69 if len(name) > 29 {70 name = name[:len(name)-6] + "..."71 }72 fmt.Printf(73 "%-6s|%-35s|%24s|%24s|%24s\n",74 line.Key,75 name,76 formatDuration(line.TimeSolution1),77 formatDuration(line.TimeSolution2),78 formatDuration(line.TimeSolution1+line.TimeSolution2),79 )80 }81 fmt.Print(82 "------------------------------------------|---------------|---------------|---------------\n",83 )84 fmt.Printf(85 "%-42s|%15s|%15s|%15s\n",86 "Total time",87 total1,88 total2,89 runTotal,90 )91 fmt.Printf("\nTotal run time (parallel runs): %s\n\n", total)92}...

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "time"3func main() {4 t := time.Now()5 p(t.Format(time.RFC3339))6 t1, e := time.Parse(time.RFC3339, "2012-11-01T22:08:41+00:00")7 p(t1)8 fmt.Println(t1)9 fmt.Println(t)10 fmt.Println(e)11 fmt.Println(t.Format("3:04PM"))12 fmt.Println(t.Format("Mon Jan _2 15:04:05 2006"))13 fmt.Println(t.Format("2006-01-02T15:04:05.999999-07:00"))14 fmt.Println(t.Format("2006-01-02T15:04:05.999999-07:00"))15 fmt.Println(t.Format(time.Kitchen))16 fmt.Println(t.Format(time.Stamp))17 fmt.Println(t.Format(time.StampMilli))18 fmt.Println(t.Format(time.StampMicro))19 fmt.Println(t.Format(time.StampNano))20 t2, e := time.Parse(form, "8 41 PM")21 p(t2)22}23import "fmt

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(time.Second)4 fmt.Println(time.Minute)5 fmt.Println(time.Hour)6}7import (8func main() {9 fmt.Println(time.Nanosecond)10 fmt.Println(time.Microsecond)11 fmt.Println(time.Millisecond)12}13import (14func main() {15 fmt.Println(time.Nanosecond)16 fmt.Println(time.Microsecond)17 fmt.Println(time.Millisecond)18 fmt.Println(time.Second)19 fmt.Println(time.Minute)20 fmt.Println(time.Hour)21}22import (23func main() {24 fmt.Println(time.Nanosecond)25 fmt.Println(time.Microsecond)26 fmt.Println(time.Millisecond)27 fmt.Println(time.Second)28 fmt.Println(time.Minute)29 fmt.Println(time.Hour)30 fmt.Println(time.Nanosecond * 100)31 fmt.Println(time.Microsecond * 100)32 fmt.Println(time.Millisecond * 100)33 fmt.Println(time.Second * 100)34 fmt.Println(time.Minute * 100)35 fmt.Println(time.Hour * 100)36}37import (38func main() {39 fmt.Println(time.Nanosecond * 100)40 fmt.Println(time.Microsecond * 100)41 fmt.Println(time.Millisecond * 100)42 fmt.Println(time.Second * 100)43 fmt.Println(time.Minute * 100)44 fmt.Println(time.Hour * 100)45}

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Duration is the representation of a span of time.")4 fmt.Println("A Duration represents the elapsed time between two instants as an int64 nanosecond count.")5 fmt.Println("The representation limits the largest representable duration to approximately 290 years.")6 fmt.Println("Duration is a signed type. The comparison operators ==, <, >, and so on compare not just the magnitude but also the sign of the duration.")7 fmt.Println("They make no allowance for magnitudes larger than the largest representable value.")8 fmt.Println("")9 fmt.Println("Duration is the representation of a span of time.")10 fmt.Println("A Duration represents the elapsed time between two instants as an int64 nanosecond count.")11 fmt.Println("The representation limits the largest representable duration to approximately 290 years.")12 fmt.Println("Duration is a signed type. The comparison operators ==, <, >, and so on compare not just the magnitude but also the sign of the duration.")13 fmt.Println("They make no allowance for magnitudes larger than the largest representable value.")14 fmt.Println("")

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Duration in hours:", time.Duration(1).Hours())4 fmt.Println("Duration in minutes:", time.Duration(1).Minutes())5 fmt.Println("Duration in seconds:", time.Duration(1).Seconds())6 fmt.Println("Duration in milliseconds:", time.Duration(1).Milliseconds())7 fmt.Println("Duration in nanoseconds:", time.Duration(1).Nanoseconds())8}

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 t := time.Duration(100000000)4 fmt.Println(t)5 fmt.Println(t.String())6 fmt.Println(t.Hours())7 fmt.Println(t.Minutes())8 fmt.Println(t.Seconds())9 fmt.Println(t.Nanoseconds())10}11import (12func main() {13 t := time.Duration(100000000)14 fmt.Println(t)15 fmt.Println(t.String())16 fmt.Println(t.Hours())17 fmt.Println(t.Minutes())18 fmt.Println(t.Seconds())19 fmt.Println(t.Nanoseconds())20}21import (22func main() {23 t := time.Duration(100000000)24 fmt.Println(t)25 fmt.Println(t.String())26 fmt.Println(t.Hours())27 fmt.Println(t.Minutes())28 fmt.Println(t.Seconds())29 fmt.Println(t.Nanoseconds())30}31import (32func main() {33 t := time.Duration(100000000)34 fmt.Println(t)35 fmt.Println(t.String())36 fmt.Println(t.Hours())37 fmt.Println(t.Minutes())38 fmt.Println(t.Seconds())39 fmt.Println(t.Nanoseconds())40}41import (42func main() {43 t := time.Duration(100000000)44 fmt.Println(t)45 fmt.Println(t.String())46 fmt.Println(t.Hours())47 fmt.Println(t.Minutes())48 fmt.Println(t.Seconds())49 fmt.Println(t.Nanoseconds())50}

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Duration in Nanoseconds:", time.Duration(1000000000).Nanoseconds())4 fmt.Println("Duration in Microseconds:", time.Duration(1000000000).Microseconds())5 fmt.Println("Duration in Milliseconds:", time.Duration(1000000000).Milliseconds())6 fmt.Println("Duration in Seconds:", time.Duration(1000000000).Seconds())7 fmt.Println("Duration in Minutes:", time.Duration(1000000000).Minutes())8 fmt.Println("Duration in Hours:", time.Duration(1000000000).Hours())9}10GoLang | time.ParseDuration() Method11func ParseDuration(s string) (Duration, error)12import (13func main() {14 fmt.Println(time.ParseDuration("1h"))15 fmt.Println(time.ParseDuration("1m"))16 fmt.Println(time.ParseDuration("1s"))17 fmt.Println(time.ParseDuration("1ms"))18 fmt.Println(time.ParseDuration("1us"))19 fmt.Println(time.ParseDuration("1ns"))20}21GoLang | time.Sleep() Method22func Sleep(d Duration)23import (24func main() {25 fmt.Println("This is first line")26 time.Sleep(3 * time.Second)27 fmt.Println("This is second line")28}29GoLang | time.Sleep() Method30The Sleep()

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Duration in nanoseconds: ", time.Duration(10000000000))4 fmt.Println("Duration in microseconds: ", time.Duration(10000000000).Microseconds())5 fmt.Println("Duration in milliseconds: ", time.Duration(10000000000).Milliseconds())6 fmt.Println("Duration in seconds: ", time.Duration(10000000000).Seconds())7 fmt.Println("Duration in minutes: ", time.Duration(10000000000).Minutes())8 fmt.Println("Duration in hours: ", time.Duration(10000000000).Hours())9 fmt.Println("Duration in days: ", time.Duration(10000000000).Hours()/24)10}11import (12func main() {13 fmt.Println("Duration in nanoseconds: ", time.Duration(10000000000).Format(" %d days %h hours %m minutes %s seconds %ms milliseconds %us microseconds %ns nanoseconds"))14 fmt.Println("Duration in microseconds: ", time.Duration(10000000000).Microseconds())15 fmt.Println("Duration in milliseconds: ", time.Duration(10000000000).Milliseconds())16 fmt.Println("Duration in seconds: ", time.Duration(10000000000).Seconds())17 fmt.Println("Duration in minutes: ", time.Duration(100000

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Duration in hours: ", time.Duration(2*time.Hour).Hours())4 fmt.Println("Duration in minutes: ", time.Duration(2*time.Hour).Minutes())5 fmt.Println("Duration in seconds: ", time.Duration(2*time.Hour).Seconds())6 fmt.Println("Duration in nanoseconds: ", time.Duration(2*time.Hour).Nanoseconds())7}82. ParseDuration() method9func ParseDuration(s string) (Duration, error)10import (11func main() {12 duration, err := time.ParseDuration("2h30m")13 if err != nil {14 fmt.Println(err)15 }16 fmt.Println("Duration in hours: ", duration.Hours())17 fmt.Println("Duration in minutes: ", duration.Minutes())18 fmt.Println("Duration in seconds: ", duration.Seconds())19 fmt.Println("Duration in nanoseconds: ", duration.Nanoseconds())20}213. Round() method22func (d Duration) Round(m Duration) Duration23import (

Full Screen

Full Screen

FormatDuration

Using AI Code Generation

copy

Full Screen

1import "time"2func main() {3 t := time.Duration(1 * time.Second)4 fmt.Println(t)5 fmt.Println(t.String())6 fmt.Println(t.Hours())7 fmt.Println(t.Minutes())8 fmt.Println(t.Seconds())9 fmt.Println(t.Nanoseconds())10}11import "time"12func main() {13 t, err := time.ParseDuration("1h30m")14 if err != nil {15 fmt.Println("Error")16 }17 fmt.Println(t)18 fmt.Println(t.Hours())19 fmt.Println(t.Minutes())20 fmt.Println(t.Seconds())21 fmt.Println(t.Nanoseconds())22}23import "time"24func main() {25 t, err := time.Parse(time.RFC3339, "2012-11-01T22:08:41+00:00")26 if err != nil {27 fmt.Println("Error")28 }29 fmt.Println(t)30}31import "time"32func main() {33 t, err := time.ParseInLocation(time.RFC3339, "2012-11-01T22:08:41+00:00", time.Local)34 if err != nil {35 fmt.Println("Error")36 }37 fmt.Println(t)38}39import "time"40func main() {41 t, err := time.ParseInLocation(time.RFC3339, "2012-11-01T22:08:41+00:00", time.UTC)42 if err != nil {43 fmt.Println("Error")44 }45 fmt.Println(t)46}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful