231 Public method to calculate the median. |
231 Public method to calculate the median. |
232 |
232 |
233 @return median line complexity value |
233 @return median line complexity value |
234 @rtype float |
234 @rtype float |
235 """ |
235 """ |
236 total = 0 |
236 lst = self.__count.values() |
237 for line in self.__count: |
|
238 total += self.__count[line] |
|
239 |
|
240 return self.__median(self.__count.values()) |
|
241 |
|
242 def __median(self, lst): |
|
243 """ |
|
244 Private method to determine the median of a list. |
|
245 |
|
246 @param lst list to determine the median for |
|
247 @type list of int |
|
248 @return median of the list |
|
249 @rtype float |
|
250 """ |
|
251 sortedList = sorted(lst) |
237 sortedList = sorted(lst) |
252 listLength = len(lst) |
238 listLength = len(lst) |
253 medianIndex = (listLength - 1) // 2 |
239 medianIndex = (listLength - 1) // 2 |
254 |
240 |
255 if (listLength % 2): |
241 if listLength == 0: |
|
242 return 0.0 |
|
243 elif (listLength % 2): |
256 return float(sortedList[medianIndex]) |
244 return float(sortedList[medianIndex]) |
257 else: |
245 else: |
258 return ( |
246 return ( |
259 (sortedList[medianIndex] + sortedList[medianIndex + 1]) / 2.0 |
247 (sortedList[medianIndex] + sortedList[medianIndex + 1]) / 2.0 |
260 ) |
248 ) |