Skip to content

Commit

Permalink
cleanup, license ect.
Browse files Browse the repository at this point in the history
  • Loading branch information
knarrff committed Mar 11, 2024
1 parent e9e811b commit 4f78714
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions plot_counter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
#!/usr/bin/env python3
""" Plot user counts for different matrix channels
Help is available with the "--help" option.
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/>.
"""

__author__ = "Frank Löffler"
__contact__ = "frank.loeffler@uni-jena.de"
__copyright__ = "Copyright 2024, Frank Löffler; 2024 Friedrich-Schiller-Universität Jena"
__date__ = "2024-03-05"
__email__ = "frank.loeffler@uni-jena.de"
__license__ = "AGPLv3"
__maintainer__ = "frank.loeffler@uni-jena.de"
__status__ = "Development"
__version__ = "0.0.1"

import sys, os
from pprint import pprint
import argparse
Expand All @@ -10,10 +35,11 @@

parser = argparse.ArgumentParser(description="")
parser.add_argument('file',
help='input json file to use')
help='input json file to use. The output of the matrixcounter.py script '
'is the intended input.')
parser.add_argument('-o', '--output',
help='output file to write the figure to; extension defines format to the'
'extend matplotlib supports')
'extend matplotlib supports; default: counter_matrix.pdf')
args = vars(parser.parse_args())

try:
Expand All @@ -34,26 +60,33 @@
xmin=datetime.fromisoformat('2999-01-01T00:00:00')
xmax=datetime.fromisoformat('1999-01-01T00:00:00')

# go through all rooms and sort by current (last) user count
for room, roomdata in sorted(data['rooms'].items(), key=lambda x: x[1]['counts'][1][-1]):
# exclude a few rooms; TODO: already do not include those numbers in the collected data
if roomdata['name'].startswith('deRSE-test'):
continue
if roomdata['name'].startswith('deRSE-alt'):
continue
if roomdata['name'].startswith('de-RSE-alt'):
continue
# convert data to the right types for plotting
times = [datetime.fromisoformat(s) for s in roomdata['counts'][0]]
counts = roomdata['counts'][1]
# add one more "fake" datapoint, as stairs() requires len(edges) = len(data)+1
times.append(times[-1])
# get global extrema as limits later
xmin = min(xmin, times[0])
xmax = max(xmax, times[-1])

# the actual plot line
ax.stairs(counts, edges=times, lw=2, label=roomdata['name'])

ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)

# limit to the observed time range and ensure ymin to be 0
ax.set_xlim(xmin=xmin, xmax=xmax)
ax.set_ylim(ymin=0)

# some plot cosmetics
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
for label in ax.get_xticklabels(which='major'):
label.set(rotation=20, horizontalalignment='right')
Expand Down

0 comments on commit 4f78714

Please sign in to comment.