ledgerUtil.py (10118B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\ledger\ledgerUtil.py 2 import collections 3 import blue 4 from collections import defaultdict 5 import evetypes 6 import gametime 7 from dogma.const import attributeOreBasicType, attributeAsteroidMetaLevel 8 from eveservices.ledger import GetLedgerService 9 import inventorycommon.const as invConst 10 from localization import GetByLabel 11 import dogma.data as dogma_data 12 NUM_DAYS_BACK = 90 13 REST_ORE = -1 14 SCROLL_HEADERS_PERSONAL = [GetByLabel('UI/Ledger/TimestampHeader'), 15 GetByLabel('UI/Ledger/OreTypeHeader'), 16 GetByLabel('UI/Ledger/OreQtyHeader'), 17 GetByLabel('UI/Ledger/OreWasteHeader'), 18 GetByLabel('UI/Common/Volume'), 19 GetByLabel('UI/Ledger/VolumeWastedHeader'), 20 GetByLabel('UI/Inventory/EstPrice'), 21 GetByLabel('UI/Ledger/WastedPriceHeader'), 22 GetByLabel('UI/Ledger/SolarSystemHeader')] 23 SCROLL_HEADERS_CORP = [GetByLabel('UI/Ledger/TimestampHeader'), 24 GetByLabel('UI/Ledger/CorpNameHeader'), 25 GetByLabel('UI/Ledger/PilotHeader'), 26 GetByLabel('UI/Ledger/OreTypeHeader'), 27 GetByLabel('UI/Ledger/OreQtyHeader'), 28 GetByLabel('UI/Common/Volume'), 29 GetByLabel('UI/Inventory/EstPrice')] 30 MOON_ORE_GROUPS = [invConst.groupUbiquitousMoonAsteroids, 31 invConst.groupCommonMoonAsteroids, 32 invConst.groupUncommonMoonAsteroids, 33 invConst.groupRareMoonAsteroids, 34 invConst.groupExceptionalMoonAsteroids] 35 DEFAULT_COLOR = (0.5, 0.5, 0.5, 1.0) 36 37 class OreInfoHelper(object): 38 39 def __init__(self): 40 self.metaLevelByOreTypeID = None 41 self.basicOreTypeByOreTypeID = None 42 self.moonBasicTypeIDs = None 43 self.colorsByMoonOreTypeID = None 44 45 def GetBasicOreForTypeID(self, typeID): 46 if self.basicOreTypeByOreTypeID is None: 47 self.basicOreTypeByOreTypeID = {} 48 for typeID, basicOreTypeID in dogma_data.get_type_and_value_by_attribute_id(attributeOreBasicType).iteritems(): 49 if basicOreTypeID: 50 self.basicOreTypeByOreTypeID[typeID] = int(basicOreTypeID) 51 52 return self.basicOreTypeByOreTypeID.get(typeID, None) 53 54 def GetMetaLevelByTypeID(self, typeID): 55 if self.metaLevelByOreTypeID is None: 56 self.metaLevelByOreTypeID = {} 57 for typeID, asteroidMetaLevel in dogma_data.get_type_and_value_by_attribute_id(attributeAsteroidMetaLevel).iteritems(): 58 self.metaLevelByOreTypeID[typeID] = int(asteroidMetaLevel) 59 60 return self.metaLevelByOreTypeID.get(typeID, 1) 61 62 63 oreInfoHelper = OreInfoHelper() 64 65 def GetBasicOreForTypeID(typeID): 66 return oreInfoHelper.GetBasicOreForTypeID(typeID) 67 68 69 def GetMetaLevelByTypeID(typeID): 70 return oreInfoHelper.GetMetaLevelByTypeID(typeID) 71 72 73 def GetMiniMapRange(): 74 now = gametime.GetWallclockTime() 75 endTime = GetMaxDayTimeStamp(now) 76 startTime = endTime - NUM_DAYS_BACK * const.DAY 77 startTime = GetMinDayTimeStamp(startTime) 78 return (startTime, endTime) 79 80 81 def GetDataForPersonaMinimap(): 82 data, _ = GetLedgerService().GetPersonalData() 83 return GetDataForMinimap(data) 84 85 86 def GetDataForCorpMinimap(structureID): 87 data = GetLedgerService().GetCorpData(structureID) 88 return GetDataForMinimap(data) 89 90 91 def GetDataForMinimap(data): 92 now = gametime.GetWallclockTime() 93 minedByDay = defaultdict(int) 94 for each in data: 95 year, month, wd, day, hour, min, sec, ms = blue.os.GetTimeParts(each.eventDate) 96 timeTuple = (year, month, day) 97 minedByDay[timeTuple] += each.quantity 98 99 startTime = now - NUM_DAYS_BACK * const.DAY 100 nextTime = startTime 101 summaryData = [] 102 while nextTime < now + const.DAY: 103 year, month, wd, day, hour, min, sec, ms = blue.os.GetTimeParts(nextTime) 104 mined = minedByDay.get((year, month, day), 0) 105 timestamp = GetMaxDayTimeStamp(nextTime) 106 summaryData.append([timestamp, mined]) 107 nextTime += const.DAY 108 109 return summaryData 110 111 112 def IsInRange(timestamp, start, end): 113 if start and timestamp < start: 114 return False 115 if end and timestamp > end: 116 return False 117 return True 118 119 120 def GetGroupingsForOreFromData(data): 121 normalOreGroupIDs = set() 122 moonTypeIDsByGroupID = defaultdict(set) 123 for each in data: 124 groupID = evetypes.GetGroupID(each.typeID) 125 if groupID in MOON_ORE_GROUPS: 126 moonTypeIDsByGroupID[groupID].add(each.typeID) 127 else: 128 normalOreGroupIDs.add(groupID) 129 130 return (normalOreGroupIDs, moonTypeIDsByGroupID) 131 132 133 def GetGroupsForData(data): 134 allCorps = set() 135 allCharIDs = set() 136 for each in data: 137 allCorps.add(each.corporationID) 138 allCharIDs.add(each.characterID) 139 140 return (allCorps, allCharIDs) 141 142 143 def GetMaxDayTimeStamp(timestamp): 144 year, month, wd, day, _, _, _, _ = blue.os.GetTimeParts(timestamp) 145 return blue.os.GetTimeFromParts(year, month, day, 23, 59, 59, 99) 146 147 148 def GetMinDayTimeStamp(timestamp): 149 year, month, wd, day, _, _, _, _ = blue.os.GetTimeParts(timestamp) 150 return blue.os.GetTimeFromParts(year, month, day, 0, 0, 0, 0) 151 152 153 def GetColorForBaseTypeID(typeID): 154 color = colorsByTypeID.get(typeID, None) 155 if color: 156 return color 157 groupID = evetypes.GetGroupID(typeID) 158 return colorsByGroupID.get(groupID, DEFAULT_COLOR) 159 160 161 colorsByGroupID = {invConst.groupArkonor: (0.957, 0.263, 0.212, 1.0), 162 invConst.groupBistot: (0.298, 0.686, 0.314, 1.0), 163 invConst.groupCrokite: (1.0, 0.792, 0.157, 1.0), 164 invConst.groupDarkOchre: (0.329, 0.431, 0.478, 1.0), 165 invConst.groupHedbergite: (0.0, 0.737, 0.831, 1.0), 166 invConst.groupHemorphite: (0.247, 0.318, 0.71, 1.0), 167 invConst.groupJaspet: (0.62, 0.62, 0.62, 1.0), 168 invConst.groupKernite: (0.949, 0.659, 0.439, 1.0), 169 invConst.groupPlagioclase: (0.38, 0.38, 0.38, 1.0), 170 invConst.groupPyroxeres: (0.62, 0.792, 0.247, 1.0), 171 invConst.groupScordite: (0.365, 0.251, 0.216, 1.0), 172 invConst.groupSpodumain: (0.0, 0.588, 0.533, 1.0), 173 invConst.groupVeldspar: (0.886, 0.808, 0.231, 1.0), 174 invConst.groupGneiss: (0.773, 0.882, 0.647, 1.0), 175 invConst.groupMercoxit: (0.957, 0.263, 0.196, 1.0), 176 invConst.groupOmber: (0.753, 0.365, 0.82, 1.0), 177 invConst.groupExceptionalMoonAsteroids: (0.776, 0.31, 0.251, 1.0), 178 invConst.groupRareMoonAsteroids: (0.431, 0.604, 0.718, 1.0), 179 invConst.groupUncommonMoonAsteroids: (0.776, 0.475, 0.247, 1.0), 180 invConst.groupCommonMoonAsteroids: (0.478, 0.686, 0.184, 1.0), 181 invConst.groupUbiquitousMoonAsteroids: (0.718, 0.659, 0.529, 1.0)} 182 colorsByTypeID = {invConst.typeClearIcicle: (0.694, 0.953, 1.0, 1.0), 183 invConst.typeGlacialMass: (0.306, 0.773, 0.808, 1.0), 184 invConst.typeBlueIce: (0.396, 0.902, 1.0, 1.0), 185 invConst.typeWhiteGlaze: (0.753, 1.0, 1.0, 1.0), 186 invConst.typeGlareCrust: (0.8, 0.843, 1.0, 1.0), 187 invConst.typeAzureIce: (0.725, 0.894, 0.953, 1.0), 188 invConst.typeCrystallineIcicle: (0.729, 0.898, 0.953, 1.0), 189 invConst.typeDarkGlitter: (0.494, 0.824, 0.929, 1.0), 190 invConst.typeEnrichedClearIcicle: (0.694, 0.953, 1.0, 1.0), 191 invConst.typeGelidus: (0.808, 0.839, 0.929, 1.0), 192 invConst.typeKrystallos: (0.725, 0.894, 0.953, 1.0), 193 invConst.typePristineWhiteGlaze: (0.753, 1.0, 1.0, 1.0), 194 invConst.typeSmoothGlacialMass: (0.306, 0.773, 0.808, 1.0), 195 invConst.typeThickBlueIce: (0.396, 0.902, 1.0, 1.0), 196 invConst.typeAmberCytoserocin: (1.0, 0.671, 0.251, 1.0), 197 invConst.typeAmberMykoserocin: (1.0, 0.671, 0.251, 1.0), 198 invConst.typeGoldenCytoserocin: (0.992, 0.847, 0.208, 1.0), 199 invConst.typeGoldenMykoserocin: (0.992, 0.847, 0.208, 1.0), 200 invConst.typeViridianCytoserocin: (0.149, 0.776, 0.855, 1.0), 201 invConst.typeViridianMykoserocin: (0.149, 0.776, 0.855, 1.0), 202 invConst.typeCeladonCytoserocin: (0.482, 0.122, 0.635, 1.0), 203 invConst.typeCeladonMykoserocin: (0.482, 0.122, 0.635, 1.0), 204 invConst.typeMalachiteCytoserocin: (0.4, 0.733, 0.416, 1.0), 205 invConst.typeMalachiteMykoserocin: (0.4, 0.733, 0.416, 1.0), 206 invConst.typeLimeCytoserocin: (0.831, 0.882, 0.341, 1.0), 207 invConst.typeLimeMykoserocin: (0.831, 0.882, 0.341, 1.0), 208 invConst.typeVermillionCytoserocin: (0.898, 0.451, 0.451, 1.0), 209 invConst.typeVermillionMykoserocin: (0.898, 0.451, 0.451, 1.0), 210 invConst.typeAzureCytoserocin: (0.012, 0.663, 0.957, 1.0), 211 invConst.typeAzureMykoserocin: (0.012, 0.663, 0.957, 1.0), 212 invConst.typeGambogeCytoserocin: (1.0, 0.596, 0.0, 1.0), 213 invConst.typeChartreuseCytoserocin: (0.612, 0.153, 0.69, 1.0), 214 invConst.typeFulleriteC50: (0.424, 0.188, 0.447, 1.0), 215 invConst.typeFulleriteC60: (0.71, 0.318, 0.749, 1.0), 216 invConst.typeFulleriteC70: (0.129, 0.588, 0.953, 1.0), 217 invConst.typeFulleriteC72: (0.247, 0.514, 0.698, 1.0), 218 invConst.typeFulleriteC84: (0.839, 0.357, 0.145, 1.0), 219 invConst.typeFulleriteC28: (0.949, 0.373, 0.173, 1.0), 220 invConst.typeFulleriteC32: (0.035, 0.718, 0.0, 1.0), 221 invConst.typeFulleriteC320: (0.035, 0.478, 0.0, 1.0), 222 invConst.typeFulleriteC540: (0.063, 0.639, 0.0, 1.0), 223 invConst.typeDysprosium: (0.776, 0.31, 0.251, 1.0), 224 invConst.typeNeodymium: (0.776, 0.31, 0.251, 1.0), 225 invConst.typePromethium: (0.776, 0.31, 0.251, 1.0), 226 invConst.typeThulium: (0.776, 0.31, 0.251, 1.0), 227 invConst.typeMercury: (0.431, 0.604, 0.718, 1.0), 228 invConst.typeCaesium: (0.431, 0.604, 0.718, 1.0), 229 invConst.typeHafnium: (0.431, 0.604, 0.718, 1.0), 230 invConst.typeTechnetium: (0.431, 0.604, 0.718, 1.0), 231 invConst.typeChromium: (0.776, 0.475, 0.247, 1.0), 232 invConst.typeVanadium: (0.776, 0.475, 0.247, 1.0), 233 invConst.typeCadmium: (0.776, 0.475, 0.247, 1.0), 234 invConst.typePlatinum: (0.776, 0.475, 0.247, 1.0), 235 invConst.typeTungsten: (0.478, 0.686, 0.184, 1.0), 236 invConst.typeTitanium: (0.478, 0.686, 0.184, 1.0), 237 invConst.typeScandium: (0.478, 0.686, 0.184, 1.0), 238 invConst.typeCobalt: (0.478, 0.686, 0.184, 1.0), 239 invConst.typeHydrocarbons: (0.718, 0.659, 0.529, 1.0), 240 invConst.typeAtmosphericGases: (0.718, 0.659, 0.529, 1.0), 241 invConst.typeEvaporiteDeposits: (0.718, 0.659, 0.529, 1.0), 242 invConst.typeSilicates: (0.718, 0.659, 0.529, 1.0)} 243 244 def GetColorsForTypeIDs(typeIDs): 245 colors = [] 246 for eachTypeID in typeIDs: 247 if eachTypeID == REST_ORE: 248 colors.append(DEFAULT_COLOR) 249 continue 250 c = GetColorForBaseTypeID(eachTypeID) 251 colors.append(c) 252 253 return colors