diff options
author | Mattias Andrée <maandree@kth.se> | 2021-02-23 01:11:51 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-02-23 01:12:15 +0100 |
commit | 33d0ee66d80d664aec3511b1827049e538642658 (patch) | |
tree | fa3e0ae6a88ff139bb37923d348562b9d851420c /src | |
parent | update dist (diff) | |
download | median-2.0.tar.gz median-2.0.tar.bz2 median-2.0.tar.xz |
Change license, rewrite in C, remove info manual, remove dist2.0
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rwxr-xr-x | src/median | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/src/median b/src/median deleted file mode 100755 index 8684cef..0000000 --- a/src/median +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python3 -# -*- python -*- -''' -median — Calculate the median values for a set of groups -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. -''' - -lines = [] -try: - while True: - lines.append(input()) -except: - pass - -get_key = lambda x : x[x.index(' '):] if ' ' in x else '' -get_value = lambda x : x[:x.index(' ')] if ' ' in x else x -lines = [(get_value(line), get_key(line)) for line in lines if not line == ''] - -lines.sort(key = lambda x : x[1]); - -last, values = None, None -lines.append((..., ...)) -for value, key in lines: - if last != key: - if last is not None: - try: - values.sort(key = lambda x : float(x)) - except: - values.sort() - if len(values) % 2 == 1: - median = values[len(values) // 2] - else: - low = values[len(values) // 2 - 1] - high = values[len(values) // 2 - 0] - try: - low_plus, low_minus, low_dot = (low[0] == '+'), (low[0] == '-'), ('.' in low) - high_plus, high_minus, high_dot = (high[0] == '+'), (high[0] == '-'), ('.' in high) - if low_plus or low_minus: low = low[1:] - if high_plus or high_minus: high = high[1:] - if not low_dot: low += '.' - if not high_dot: high += '.' - lowi , lowd = [len(x) for x in low.split('.')] - highi, highd = [len(x) for x in high.split('.')] - if lowd < highd: low += '0' - if lowd > highd: high += '0' - mediani = max(lowi, highi) - mediand = max(lowd, highd) - median = float(low) * (-1 if low_minus else 1) - median += float(high) * (-1 if high_minus else 1) - negative, median = median < 0, abs(median) / 2 - if (int(low.replace('.', '')[-1]) + int(high.replace('.', '')[-1])) % 2 == 1: - mediand += 1 - if mediand == 0: - median = '%%0%ii' % mediani % median - if low_dot or high_dot: - median += '.' - else: - median = '%%0%i.%if' % (max(1, mediani) + mediand + 1, mediand) % median - if mediani == 0: - median = median[1:] - if low_minus and high_minus: prefix = '-' - elif negative: prefix = '-' - elif low_plus or high_plus: prefix = '+' - elif low_minus or high_minus: prefix = '0' - else: prefix = '' - median = prefix + median - except: - median = values[len(values) // 2 - 1] - print(median + last) - last, values = key, [] - values.append(value) - |