00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import time
00019 from objects.logic.utils.timeUtil import timeUtil
00020
00021
00022
00023
00024
00025
00026 class entityDisplayer():
00027
00028
00029 def __init__(self, dispConfigurator):
00030 self.setDisplayConfigurator(dispConfigurator)
00031
00032
00033
00034 def setDisplayConfigurator(self, dispConfigurator):
00035 self.dispConfig = dispConfigurator
00036 self.setScales()
00037
00038
00039
00040
00041 def setScales(self):
00042 self.displayTransferScale = self.dispConfig.glb_getDisplayScale()
00043 self.displayFadeTime = self.dispConfig.glb_getFadeTime()
00044
00045
00046 if self.displayFadeTime <= 0:
00047 self.displayFadeTime = 1
00048
00049
00050
00051
00052 def _getAlpha(self, networkEntity):
00053 timeNow = time.time()
00054
00055 timDelta = (timeNow - networkEntity.lastUpdateTS)
00056
00057
00058 if (self.displayFadeTime - timDelta) < 0: return 0.08
00059
00060 alpha = (self.displayFadeTime - timDelta) / self.displayFadeTime
00061
00062
00063 return alpha
00064
00065
00066
00067 def _getLineWidth(self, totBytes):
00068
00069
00070
00071
00072
00073
00074 if totBytes >= 0 and totBytes < 1 * self.displayTransferScale:
00075 return 0.4
00076 elif totBytes >= 1 * self.displayTransferScale and totBytes < 3 * self.displayTransferScale:
00077 return 0.8
00078 elif totBytes >= 3 * self.displayTransferScale and totBytes < 5 * self.displayTransferScale:
00079 return 1.2
00080 else:
00081 return 1.6
00082
00083
00084
00085
00086 def getAttributesFromEntity(self, networkEntity):
00087
00088 displayAttributes = dict()
00089 timeNow = time.time()
00090
00091 """
00092 figure out the alpha value for the line
00093 based on how idle the peer is
00094 """
00095 displayAttributes["lineAlpha"] = self._getAlpha(networkEntity)
00096
00097 displayAttributes["marker"] = "ro"
00098
00099
00100 if networkEntity.exactLocation == True:
00101 displayAttributes["lineStyle"] = "-"
00102 else:
00103 displayAttributes["lineStyle"] = ":"
00104
00105
00106 displayAttributes["label"] = self.getEntLabelFromConfigValue(networkEntity, self.dispConfig.glb_getDisplayLabel())
00107
00108
00109 displayAttributes["lineWidth"] = self._getLineWidth(networkEntity.totalBytes)
00110
00111 if networkEntity.totalBytes >= 0 and networkEntity.totalBytes < 1 * self.displayTransferScale:
00112 displayAttributes["markerSize"] = 4
00113 elif networkEntity.totalBytes >= 1 * self.displayTransferScale and networkEntity.totalBytes < 3 * self.displayTransferScale:
00114 displayAttributes["markerSize"] = 6
00115 elif networkEntity.totalBytes >= 3 * self.displayTransferScale and networkEntity.totalBytes < 5 * self.displayTransferScale:
00116 displayAttributes["markerSize"] = 8
00117 else:
00118 displayAttributes["markerSize"] = 10
00119
00120 return displayAttributes
00121
00122
00123
00124
00125
00126 def getAttributesFromList(self, entityList):
00127
00128 displayAttributes = dict()
00129 totBytes = 0
00130 totAlpha = 0
00131 atleastOneExactLocation = False
00132 atleastOneApproxLocation = False
00133
00134 for netEnt in entityList:
00135 totBytes += netEnt.totalBytes
00136 if netEnt.exactLocation == True:
00137 atleastOneExactLocation = True
00138 else:
00139 atleastOneApproxLocation = True
00140
00141 totAlpha += self._getAlpha(netEnt)
00142
00143
00144
00145 if atleastOneExactLocation == True and atleastOneApproxLocation == True:
00146 displayAttributes["lineStyle"] = "-."
00147 elif atleastOneExactLocation == True and atleastOneApproxLocation == False:
00148 displayAttributes["lineStyle"] = "-"
00149 else:
00150 displayAttributes["lineStyle"] = ":"
00151
00152
00153 displayAttributes["label"] = "(x%d)" % (len(entityList))
00154 displayAttributes["markerSize"] = 10
00155 displayAttributes["marker"] = "r+"
00156 displayAttributes["lineWidth"] = self._getLineWidth(totBytes)
00157
00158
00159
00160
00161 displayAttributes["lineAlpha"] = totAlpha/float(len(entityList))
00162
00163
00164 return displayAttributes
00165
00166
00167
00168
00169
00170
00171
00172 def getEntLabelFromConfigValue(self, ent, userFriendlyName):
00173 retValue = ""
00174 if userFriendlyName.upper() == "PROCESS NAME" or userFriendlyName.upper() == "_DEFAULT_":
00175 retValue = ent.processName
00176 elif userFriendlyName.upper() == "IP ADDRESS":
00177 retValue = ent.foreignIPAddress
00178 elif userFriendlyName.upper() == "SRC. PORT":
00179 retValue = str(ent.selfPort)
00180 elif userFriendlyName.upper() == "DEST. PORT":
00181 retValue = str(ent.foreignPort)
00182 elif userFriendlyName.upper() == "CONN. SINCE":
00183 retValue = timeUtil.formatDateTime(ent.since)
00184 elif userFriendlyName.upper() == "IDLE TIME":
00185 retValue = timeUtil.formatTimeDiff(time.time() - ent.lastUpdateTS)
00186 elif userFriendlyName.upper() == "KB TRANSFER":
00187 retValue = "%6.2f Kb" % (ent.totalBytes / 1000)
00188 elif userFriendlyName.upper() == "CITY":
00189 retValue = ent.foreignCity
00190 elif userFriendlyName.upper() == "ISP":
00191 retValue = ent.foreignISP
00192 elif userFriendlyName.upper() == "ORGANIZATION":
00193 retValue = ent.foreignOrganization
00194 else:
00195 retValue = "No Conversion"
00196
00197 if retValue == None or retValue == "":
00198 retValue = "Unknown"
00199
00200 return retValue
00201
00202