github.com/braveheart12/just@v0.8.7/testutils/pulsarmodel/statistic.go (about) 1 /* 2 * Copyright 2019 Insolar Technologies 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "time" 22 ) 23 24 type SignalStatistic struct { 25 from int 26 to int 27 id int 28 time time.Time 29 } 30 31 type Signal struct { 32 from int 33 id int 34 } 35 36 func calculateLoad() { 37 percentiles := make(map[int]map[int]time.Time) 38 39 ticker := time.NewTicker(time.Second) 40 go func() { 41 for range ticker.C { 42 fmt.Println() 43 fmt.Println(" ----- start -------") 44 for id, sygnalStat := range percentiles { 45 percent := float64(len(sygnalStat)*100) / float64(len(network)) 46 var maxTime time.Time 47 var minTime time.Time 48 for _, t := range sygnalStat { 49 if maxTime.IsZero() { 50 maxTime = t 51 } 52 if minTime.IsZero() { 53 minTime = t 54 } 55 56 if t.After(maxTime) { 57 maxTime = t 58 } 59 if t.Before(minTime) { 60 minTime = t 61 } 62 63 } 64 fmt.Println(fmt.Sprintf("signal - %v, percent - %v, time - %v", id, percent, maxTime.Sub(minTime).Seconds())) 65 } 66 fmt.Println("-------------------") 67 } 68 }() 69 70 for event := range commonBus { 71 value, ok := percentiles[event.id] 72 if !ok { 73 percentiles[event.id] = make(map[int]time.Time) 74 value = percentiles[event.id] 75 } 76 77 _, ok = value[event.to] 78 if !ok { 79 value[event.to] = event.time 80 } 81 } 82 }