remove dumps and trash

add some new files and services

add hwtools that shows the current and last GWs - not yet included the user stats (if any available)
This commit is contained in:
2020-07-07 19:00:49 +02:00
parent 6fd36640c3
commit 40d569158f
10850 changed files with 106978 additions and 9003248 deletions
@@ -0,0 +1,122 @@
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// clanWarGetInfo, err := UnmarshalClanWarGetInfo(bytes)
// bytes, err = clanWarGetInfo.Marshal()
package main
import (
"hwcollector/server/models/common"
jsoniter "github.com/json-iterator/go"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
func UnmarshalClanWarGetInfo(data []byte) (ClanWarGetInfo, error) {
var r ClanWarGetInfo
err := json.Unmarshal(data, &r)
return r, err
}
func (r *ClanWarGetInfo) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type ClanWarGetInfo struct {
Data float64 `json:"data"`
Headers common.Headers `json:"headers"`
Response ClanWarGetInfoResponse `json:"response"`
}
type ClanWarGetInfoResponse struct {
Ident string `json:"ident"`
Result Result `json:"result"`
}
type Result struct {
Response ResultResponse `json:"response"`
}
type ResultResponse struct {
ArePointsMax bool `json:"arePointsMax"`
AvgLevel string `json:"avgLevel"`
ClanTries map[string]int64 `json:"clanTries"`
Day string `json:"day"`
EndTime int64 `json:"endTime"`
EnemyClan EnemyClan `json:"enemyClan"`
EnemyClanMembers map[string]EnemyClanMember `json:"enemyClanMembers"`
EnemyClanTries map[string]int64 `json:"enemyClanTries"`
EnemyID string `json:"enemyId"`
EnemyPoints string `json:"enemyPoints"`
EnemySlots map[string]Slot `json:"enemySlots"`
League string `json:"league"`
MyTries int64 `json:"myTries"`
NextLockTime int64 `json:"nextLockTime"`
NextWarTime int64 `json:"nextWarTime"`
OurSlots map[string]Slot `json:"ourSlots"`
Points string `json:"points"`
Season string `json:"season"`
}
type EnemyClan struct {
Country string `json:"country"`
Description string `json:"description"`
Disbanding bool `json:"disbanding"`
FrameID int64 `json:"frameId"`
ID string `json:"id"`
Level string `json:"level"`
MembersCount string `json:"membersCount"`
MinLevel string `json:"minLevel"`
OwnerID string `json:"ownerId"`
RoleNames []interface{} `json:"roleNames"`
ServerID string `json:"serverId"`
Title string `json:"title"`
TopActivity string `json:"topActivity"`
TopDungeon string `json:"topDungeon"`
}
type EnemyClanMember struct {
AllowPm string `json:"allowPm"`
AvatarID string `json:"avatarId"`
ClanID string `json:"clanId"`
ClanRole string `json:"clanRole"`
ClanTitle string `json:"clanTitle"`
FrameID int64 `json:"frameId"`
ID string `json:"id"`
IsChatModerator bool `json:"isChatModerator"`
LastLoginTime string `json:"lastLoginTime"`
LeagueID int64 `json:"leagueId"`
Level string `json:"level"`
Name string `json:"name"`
ServerID string `json:"serverId"`
}
type Slot struct {
AttackerID int64 `json:"attackerId"`
PointsFarmed int64 `json:"pointsFarmed"`
SlotID int64 `json:"slotId"`
Status string `json:"status"`
TargetMarkingUserID *int64 `json:"targetMarkingUserId,omitempty"`
Team []map[string]Team `json:"team"`
TotalPoints int64 `json:"totalPoints"`
User EnemyClanMember `json:"user"`
}
type Team struct {
Color *int64 `json:"color,omitempty"`
ID int64 `json:"id"`
Level int64 `json:"level"`
Power int64 `json:"power"`
Star int64 `json:"star"`
State State `json:"state"`
Type string `json:"type"`
}
type State struct {
Energy int64 `json:"energy"`
HP int64 `json:"hp"`
IsDead bool `json:"isDead"`
MaxHP int64 `json:"maxHp"`
}
+17
View File
@@ -0,0 +1,17 @@
package common
type Headers struct {
ContentType string `json:"Content-Type"`
XAuthApplicationID string `json:"X-Auth-Application-Id"`
XAuthNetworkIdent string `json:"X-Auth-Network-Ident"`
XAuthPlayerID string `json:"X-Auth-Player-Id"`
XAuthSessionID string `json:"X-Auth-Session-Id"`
XAuthSessionKey string `json:"X-Auth-Session-Key"`
XAuthSignature string `json:"X-Auth-Signature"`
XAuthToken string `json:"X-Auth-Token"`
XAuthUserID string `json:"X-Auth-User-Id"`
XEnvLibraryVersion string `json:"X-Env-Library-Version"`
XRequestID string `json:"X-Request-Id"`
XRequestedWith string `json:"X-Requested-With"`
XServerTime string `json:"X-Server-Time"`
}
File diff suppressed because it is too large Load Diff
+108
View File
@@ -0,0 +1,108 @@
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// qtmodels, err := UnmarshalQtmodels(bytes)
// bytes, err = qtmodels.Marshal()
package qtmodels
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestUnmarshalQtmodels(t *testing.T) {
defaultPath, _ := os.Getwd()
defaultPath, _ = filepath.Abs(defaultPath)
defaultPath = filepath.Join(defaultPath, "..", "..", "..", "data")
fs := []string{
defaultPath + "/arenaAttack_merged.json",
}
for _, v := range fs {
t.Run("json: "+string(v), func(t *testing.T) {
b, err := ioutil.ReadFile(v)
if err != nil {
t.Errorf("ioutil.ReadFile() error = %v", err)
return
}
qtmodels, err := UnmarshalQtmodels(b)
if err != nil {
t.Errorf("UnmarshalQtmodels() error = %v", err)
return
}
for _, qtmodel := range qtmodels {
if qtmodel.Request.Call.Name != "arenaAttack" {
t.Error(`qtmodel.Request.Call.Name != "arenaAttack"`)
return
}
}
//t.Logf("%#v", qtmodels)
})
}
}
func TestUnmarshalQtmodel(t *testing.T) {
defaultPath, _ := os.Getwd()
defaultPath, _ = filepath.Abs(defaultPath)
defaultPath = filepath.Join(defaultPath, "..", "..", "..", "data", "arenaAttack")
var fs []string
err := filepath.Walk(defaultPath, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
fs = append(fs, path)
}
return nil
})
if err != nil {
t.Errorf("Walk err = %v", err)
return
}
for _, v := range fs {
t.Run("json: "+string(v), func(t *testing.T) {
b, err := ioutil.ReadFile(v)
if err != nil {
t.Errorf("ioutil.ReadFile() error = %v", err)
return
}
qtmodel, err := UnmarshalQtmodel(b)
if err != nil {
t.Errorf("UnmarshalQtmodel() error = %v", err)
return
}
if qtmodel.Request.Call.Name != "arenaAttack" {
t.Error(`qtmodel.Request.Call.Name != "arenaAttack"`)
return
}
if qtmodel.Response.Result.Response != nil {
if qtmodel.Response.Result.Response.Battles != nil {
//t.Logf("%#v", qtmodel.Response.Result.Response.Battles)
if len(qtmodel.Response.Result.Response.Battles) != 1 {
t.Errorf(`len(qtmodel.Response.Result.Response.Battles) != 6 got %v`, len(qtmodel.Response.Result.Response.Battles))
return
}
for _, battle := range qtmodel.Response.Result.Response.Battles {
if len(battle.Attackers) == 0 {
t.Errorf(`range qtmodel.Response.Result.Response.Battles: battle.Attackers > 0 got %v`, len(battle.Attackers))
return
}
if len(battle.Defenders) == 0 {
t.Errorf(`range qtmodel.Response.Result.Response.Battles: battle.Defenders > 0 got %v`, len(battle.Defenders))
return
}
}
}
//t.Logf("%#v", qtmodels)
}
})
}
}
+70
View File
@@ -0,0 +1,70 @@
package models
import (
"encoding/json"
"strconv"
"time"
)
// UnmarshalUserJSON ...
func (u *User) UnmarshalUserJSON(data []byte) error {
var f interface{}
err := json.Unmarshal(data, &f)
if err != nil {
return err
}
m := f.(map[string]interface{})
for k, v := range m {
switch k {
case "allowPm":
u.AllowPm = v.(string)
case "avatarId":
u.AvatarID = v.(string)
case "clanId":
u.ClanID, _ = strconv.ParseUint(v.(string), 10, 64)
case "clanRole":
u.ClanRole = v.(string)
case "clanTitle":
u.ClanTitle = v.(string)
case "id":
u.ID, _ = strconv.ParseUint(v.(string), 10, 64)
case "isChatModerator":
u.IsChatModerator = v.(bool)
case "lastLoginTime":
unixTimeStamp, _ := strconv.ParseInt(v.(string), 10, 64)
u.LastLoginTime = time.Unix(unixTimeStamp, 0)
case "leagueId":
var leagueID *int64
if v != nil {
l := int64(v.(float64))
leagueID = &l
}
u.LeagueID = leagueID
case "level":
u.Level = v.(string)
case "name":
u.Name = v.(string)
case "serverId":
u.ServerID = v.(string)
}
}
return nil
}
// User ...
// used in
// - arenaAttack
type User struct {
ID uint64 `json:"id"`
AllowPm string `json:"allowPm"`
AvatarID string `json:"avatarId"`
ClanID uint64 `json:"clanId"`
ClanRole string `json:"clanRole"`
ClanTitle string `json:"clanTitle"`
IsChatModerator bool `json:"isChatModerator"`
LastLoginTime time.Time `json:"lastLoginTime"`
LeagueID *int64 `json:"leagueId"`
Level string `json:"level"`
Name string `json:"name"`
ServerID string `json:"serverId"`
}