-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
197 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
""" | ||
The latest version of this package is available at: | ||
<http://github.com/jantman/wifi-survey-heatmap> | ||
################################################################################## | ||
Copyright 2017 Jason Antman <[email protected]> <http://www.jasonantman.com> | ||
This file is part of wifi-survey-heatmap, also known as wifi-survey-heatmap. | ||
wifi-survey-heatmap is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
wifi-survey-heatmap 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 Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with wifi-survey-heatmap. If not, see <http://www.gnu.org/licenses/>. | ||
The Copyright and Authors attributions contained herein may not be removed or | ||
otherwise altered, except to add the Author attribution of a contributor to | ||
this work. (Additional Terms pursuant to Section 7b of the AGPL v3) | ||
################################################################################## | ||
While not legally required, I sincerely request that anyone who finds | ||
bugs please submit them at <https://github.com/jantman/wifi-survey-heatmap> or | ||
to me via email, and that you send any contributions or improvements | ||
either as a pull request on GitHub, or to me via email. | ||
################################################################################## | ||
AUTHORS: | ||
Jason Antman <[email protected]> <http://www.jasonantman.com> | ||
################################################################################## | ||
""" | ||
|
||
import sys | ||
import argparse | ||
import logging | ||
import json | ||
from collections import defaultdict | ||
|
||
from wifi_survey_heatmap.heatmap import HeatMapGenerator | ||
|
||
FORMAT = "[%(asctime)s %(levelname)s] %(message)s" | ||
logging.basicConfig(level=logging.WARNING, format=FORMAT) | ||
logger = logging.getLogger() | ||
|
||
|
||
class ThresholdGenerator(object): | ||
|
||
def generate(self, titles): | ||
res = defaultdict(dict) | ||
items = [HeatMapGenerator(None, t).load_data() for t in titles] | ||
for key in HeatMapGenerator.graphs.keys(): | ||
res[key]['min'] = min([ | ||
min(x[key]) for x in items | ||
]) | ||
res[key]['max'] = max([ | ||
max(x[key]) for x in items | ||
]) | ||
with open('thresholds.json', 'w') as fh: | ||
fh.write(json.dumps(res)) | ||
logger.info('Wrote: thresholds.json') | ||
|
||
|
||
def parse_args(argv): | ||
""" | ||
parse arguments/options | ||
this uses the new argparse module instead of optparse | ||
see: <https://docs.python.org/2/library/argparse.html> | ||
""" | ||
p = argparse.ArgumentParser( | ||
description='wifi survey heatmap threshold generator' | ||
) | ||
p.add_argument('-v', '--verbose', dest='verbose', action='count', default=0, | ||
help='verbose output. specify twice for debug-level output.') | ||
p.add_argument( | ||
'TITLE', type=str, help='Title for survey (and data filename)', | ||
nargs='+' | ||
) | ||
args = p.parse_args(argv) | ||
return args | ||
|
||
|
||
def set_log_info(): | ||
"""set logger level to INFO""" | ||
set_log_level_format(logging.INFO, | ||
'%(asctime)s %(levelname)s:%(name)s:%(message)s') | ||
|
||
|
||
def set_log_debug(): | ||
"""set logger level to DEBUG, and debug-level output format""" | ||
set_log_level_format( | ||
logging.DEBUG, | ||
"%(asctime)s [%(levelname)s %(filename)s:%(lineno)s - " | ||
"%(name)s.%(funcName)s() ] %(message)s" | ||
) | ||
|
||
|
||
def set_log_level_format(level, format): | ||
""" | ||
Set logger level and format. | ||
:param level: logging level; see the :py:mod:`logging` constants. | ||
:type level: int | ||
:param format: logging formatter format string | ||
:type format: str | ||
""" | ||
formatter = logging.Formatter(fmt=format) | ||
logger.handlers[0].setFormatter(formatter) | ||
logger.setLevel(level) | ||
|
||
|
||
def main(): | ||
args = parse_args(sys.argv[1:]) | ||
|
||
# set logging level | ||
if args.verbose > 1: | ||
set_log_debug() | ||
elif args.verbose == 1: | ||
set_log_info() | ||
|
||
ThresholdGenerator().generate(args.TITLE) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |