aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheather <unknown>2011-05-26 21:40:48 -0400
committerheather <unknown>2011-05-26 21:40:48 -0400
commitcf946934a4d16fc227aa5ae908c73c57e7ba6dc6 (patch)
tree1a2d4503a0b1e573c68379a69706b7dc2fbc6d11
parentb0a67d8900e5ce40d491af2efe755881ae3d51f3 (diff)
downloadd2-cf946934a4d16fc227aa5ae908c73c57e7ba6dc6.tar.bz2
d2-cf946934a4d16fc227aa5ae908c73c57e7ba6dc6.tar.xz
d2-cf946934a4d16fc227aa5ae908c73c57e7ba6dc6.zip
clean up and add conference rooms
-rw-r--r--lib/d2/app/model/generate_svg_text.py8
-rwxr-xr-x[-rw-r--r--]lib/d2/bin/d2_svg_processor.py163
2 files changed, 100 insertions, 71 deletions
diff --git a/lib/d2/app/model/generate_svg_text.py b/lib/d2/app/model/generate_svg_text.py
index 0c917ab..c56784a 100644
--- a/lib/d2/app/model/generate_svg_text.py
+++ b/lib/d2/app/model/generate_svg_text.py
@@ -53,12 +53,14 @@ class Svg(object):
53 FONT_COLOR = {u'Person': 'blue', 53 FONT_COLOR = {u'Person': 'blue',
54 u'Conference Room': 'green', 54 u'Conference Room': 'green',
55 u'Work Area': 'cyan', 55 u'Work Area': 'cyan',
56 u'Empty': 'red'} 56 u'Empty': 'red',
57 u'Restroom': 'coral'}
57 58
58 FONT_SIZE = {u'Person': '6', 59 FONT_SIZE = { u'Person': '6',
59 u'Conference Room': '6', 60 u'Conference Room': '6',
60 u'Work Area': '6', 61 u'Work Area': '6',
61 u'Empty': '6'} 62 u'Empty': '6',
63 u'Restroom': '6'}
62 64
63 def __init__(self): 65 def __init__(self):
64 self.svgText = SvgText() 66 self.svgText = SvgText()
diff --git a/lib/d2/bin/d2_svg_processor.py b/lib/d2/bin/d2_svg_processor.py
index d3d7815..cd645e2 100644..100755
--- a/lib/d2/bin/d2_svg_processor.py
+++ b/lib/d2/bin/d2_svg_processor.py
@@ -79,12 +79,23 @@ NAME_CORRECTIONS = {u'Deb Smith': u'Deborah Smith',
79 u'Sally Babcock': u'Sally Schriner', 79 u'Sally Babcock': u'Sally Schriner',
80 u'Brian Staneck': u'Brian Stanek'} 80 u'Brian Staneck': u'Brian Stanek'}
81 81
82# data from Marc's spreadsheet and conference spreadsheet
83# floor_plan_by_ntwk_id has the structure of
84# {room_name: {ntwk_id} (name, net_jack1, net_jack2)}
82floor_plan_by_ntwk_id = {} 85floor_plan_by_ntwk_id = {}
83 86
87# data from Marc's spreadsheet and conference spreadsheet
88# floor_plan_by_name has the structure of
89# {room_name: {name}: ntwk_id}
84floor_plan_by_name = {} 90floor_plan_by_name = {}
85 91
92# every plot has a ntwk_number associated with it
93# ntwk_number_data has the structure of
94# {room_name: {ntwk_id: {x: x, y:y, plot_id:plot_id}}}
86ntwk_number_data = {} 95ntwk_number_data = {}
87 96
97# manually_added_plot store the coords
98# {room_name: {ntwk_id: (x, y)}}
88manually_added_plot = {} 99manually_added_plot = {}
89 100
90NTWK_ID_PATTERN = re.compile("([A-Z]+)(\d+)") 101NTWK_ID_PATTERN = re.compile("([A-Z]+)(\d+)")
@@ -199,7 +210,7 @@ class ParseFloorPlanConferenceRoomXLS(object):
199 210
200 MULTIPLE_NTWK_ID_IN_ONE_ROOM_ERROR = "Data Error: floor plan xls has "\ 211 MULTIPLE_NTWK_ID_IN_ONE_ROOM_ERROR = "Data Error: floor plan xls has "\
201 "multiple records for ntwk_id {0} in room {1}" 212 "multiple records for ntwk_id {0} in room {1}"
202 MULTIPLE_NAME_IN_ONE_ROOM_ERROR = "Warning: floor plan xls has "\ 213 MULTIPLE_NAME_IN_ONE_ROOM_WARNING = "Warning: floor plan xls has "\
203 "multiple records for name {0} in room {1}" 214 "multiple records for name {0} in room {1}"
204 215
205 def __init__(self): 216 def __init__(self):
@@ -241,7 +252,7 @@ class ParseFloorPlanConferenceRoomXLS(object):
241 252
242 if name.lower() in floor_plan_by_name[room_name]: 253 if name.lower() in floor_plan_by_name[room_name]:
243 self._log_obj.error( 254 self._log_obj.error(
244 self.MULTIPLE_NAME_IN_ONE_ROOM_ERROR.format( 255 self.MULTIPLE_NAME_IN_ONE_ROOM_WARNING.format(
245 name.lower(), 256 name.lower(),
246 room_name)) 257 room_name))
247 else: 258 else:
@@ -383,7 +394,7 @@ class PopulateTables(object):
383 "network label in same room: {0}, {1}" 394 "network label in same room: {0}, {1}"
384 NO_CLOSEBY_NTWK_ID_ERROR = "Data Error: cannot find closest_ntwk_id "\ 395 NO_CLOSEBY_NTWK_ID_ERROR = "Data Error: cannot find closest_ntwk_id "\
385 "in room_name: {0}, x: {1} y: {2}, current name shown {3}" 396 "in room_name: {0}, x: {1} y: {2}, current name shown {3}"
386 NO_AREA_INFO_ERROR = "Data Error: cannot find area info for {0} {1}" 397 NO_AREA_INFO_WARNING = "Warning: cannot find area info for {0} {1}"
387 NO_OCCUPANT_DETAIL = "Data Error: cannot find {0} in occupant_detail" 398 NO_OCCUPANT_DETAIL = "Data Error: cannot find {0} in occupant_detail"
388 399
389 400
@@ -479,10 +490,8 @@ class PopulateTables(object):
479 plot_id) 490 plot_id)
480 491
481 def _add_manually_added_plots(self): 492 def _add_manually_added_plots(self):
482 #TODO: manually added plots need to be in svg as well
483 for (room_name, info) in manually_added_plot.items(): 493 for (room_name, info) in manually_added_plot.items():
484 for (ntwk_id, xy_info) in info.items(): 494 for (ntwk_id, xy_info) in info.items():
485 print ntwk_id, xy_info.abs_x, xy_info.abs_y
486 plot_id = self._add_to_tables(xy_info.abs_x, 495 plot_id = self._add_to_tables(xy_info.abs_x,
487 xy_info.abs_y, 496 xy_info.abs_y,
488 ntwk_id) 497 ntwk_id)
@@ -665,59 +674,78 @@ class PopulateTables(object):
665 view_box_xmin, 674 view_box_xmin,
666 view_box_ymin, 675 view_box_ymin,
667 view_box_height) 676 view_box_height)
668 if approx_room_name == '3D13A1': 677 self._process_info_given_x_y(approx_room_name,
669 room_name = self._determine_3D1_or_3A1(abs_x) 678 current_name_shown,
670 else: 679 abs_x,
671 room_name = approx_room_name 680 abs_y)
672 681
673 if room_name: #ignore cubes in btw rooms 682 def _process_info_given_x_y(self, approx_room_name, current_name_shown,
674 closest_ntwk_id = self._get_closest_ntwk_id( 683 abs_x, abs_y):
675 room_name, 684 if approx_room_name == '3D13A1':
676 abs_x, 685 room_name = self._determine_3D1_or_3A1(abs_x)
677 abs_y) 686 else:
678 if el.attrib['id'] == "AREA_ID-6": 687 room_name = approx_room_name
679 print "closest_ntwk_id: ", closest_ntwk_id, room_name 688
680 689 if room_name: #ignore cubes in btw rooms
681 if not closest_ntwk_id: 690 closest_ntwk_id = self._find_closest_ntwk_id(room_name,
682 print "looking for XXX{0}XXX".format(current_name_shown.lower()) 691 abs_x, abs_y, current_name_shown)
683 # try to find ntwk_id using floor_plan_by_name 692 if closest_ntwk_id:
684 if current_name_shown.lower() in \ 693 self._find_area_info(room_name,
685 floor_plan_by_name[room_name]: 694 closest_ntwk_id,
686 closest_ntwk_id = floor_plan_by_name[ 695 current_name_shown,
687 room_name][ 696 abs_x,
688 current_name_shown.lower()] 697 abs_y)
689 print "USE floor_plan_by_name ", closest_ntwk_id 698 else:
690 else: 699 self._log_obj.error(
691 # try to trim "conference room" for match 700 self.NO_CLOSEBY_NTWK_ID_ERROR.format(room_name,
692 conf_room_name = current_name_shown.lower()\ 701 abs_x,
693 .replace(" conference room", "") 702 abs_y,
694 print "looking for XXX{0}XXX".format(conf_room_name) 703 current_name_shown))
695 if conf_room_name in \ 704
696 floor_plan_by_name[room_name]: 705
697 closest_ntwk_id = floor_plan_by_name[ 706 def _find_area_info(self, room_name, closest_ntwk_id, current_name_shown,
698 room_name][ 707 abs_x, abs_y):
708 plot_id = ntwk_number_data[room_name][closest_ntwk_id]['plot_id']
709 self._add_label_coord(plot_id, abs_x, abs_y)
710
711 # try to find it in the spreadsheet
712 info = self._get_area_info(room_name, closest_ntwk_id)
713
714 if info:
715 self._add_ntwk_jacks(plot_id, info)
716 occupant_id = self._find_occupant_id(info.name)
717 if occupant_id:
718 self._add_to_forge(plot_id, occupant_id)
719
720 else:
721 self._log_obj.error(self.NO_AREA_INFO_WARNING.format(room_name,
722 closest_ntwk_id))
723 # no cube info found in spreadsheet,
724 # try occupant current_name_shown as occupant
725 occupant_id = self._find_occupant_id(current_name_shown)
726 if occupant_id:
727 self._add_to_forge(plot_id, occupant_id)
728
729
730
731 def _find_closest_ntwk_id(self, room_name, abs_x, abs_y, current_name_shown):
732 # first brute force to try to find it
733 closest_ntwk_id = self._get_closest_ntwk_id(room_name, abs_x, abs_y)
734
735 # try to find ntwk_id using floor_plan_by_name
736 if not closest_ntwk_id:
737 if current_name_shown.lower() in floor_plan_by_name[room_name]:
738 closest_ntwk_id = floor_plan_by_name[room_name
739 ][current_name_shown.lower()]
740 else:
741 # try to trim "conference room" for a match
742 conf_room_name = current_name_shown.lower()\
743 .replace(" conference room", "")
744 if conf_room_name in floor_plan_by_name[room_name]:
745 closest_ntwk_id = floor_plan_by_name[room_name][
699 conf_room_name] 746 conf_room_name]
700 print "USE floor_plan_by_name ", closest_ntwk_id
701 if not closest_ntwk_id:
702 self._log_obj.error(
703 self.NO_CLOSEBY_NTWK_ID_ERROR.format(
704 room_name,
705 abs_x,
706 abs_y,
707 current_name_shown))
708 else:
709 info = self._get_area_info(room_name,
710 closest_ntwk_id)
711 if info:
712 plot_id = ntwk_number_data[room_name]\
713 [closest_ntwk_id]\
714 ['plot_id']
715 self._add_ntwk_jacks(plot_id, info)
716 self._add_label_coord(plot_id, abs_x, abs_y)
717 occupant_id = self._find_occupant_id(info)
718 if occupant_id:
719 self._add_to_forge(plot_id, occupant_id)
720 747
748 return closest_ntwk_id
721 749
722 def _create_tables(self): 750 def _create_tables(self):
723 for name in reversed(self.TABLES): 751 for name in reversed(self.TABLES):
@@ -823,10 +851,6 @@ class PopulateTables(object):
823 if normalized_id_IDF in floor_plan_by_ntwk_id[room_name]: 851 if normalized_id_IDF in floor_plan_by_ntwk_id[room_name]:
824 info = floor_plan_by_ntwk_id[room_name][ 852 info = floor_plan_by_ntwk_id[room_name][
825 normalized_id_IDF] 853 normalized_id_IDF]
826 else:
827 self._log_obj.error(self.NO_AREA_INFO_ERROR.format(
828 room_name,
829 ntwk_id))
830 return info 854 return info
831 855
832 def _get_first_last_name(self, s): 856 def _get_first_last_name(self, s):
@@ -840,15 +864,15 @@ class PopulateTables(object):
840 last_name = s[first_space_idx+1:] 864 last_name = s[first_space_idx+1:]
841 return (first_name.lower().strip(), last_name.lower().strip()) 865 return (first_name.lower().strip(), last_name.lower().strip())
842 866
843 def _find_occupant_id(self, info): 867 def _find_occupant_id(self, name):
844 occupant_id = None 868 occupant_id = None
845 if info.name == "Open": 869 if name == "Open":
846 empty = self._db.session.query(Occupant).filter( 870 empty = self._db.session.query(Occupant).filter(
847 "occupant_type_id=:occupant_type_id").params( 871 "occupant_type_id=:occupant_type_id").params(
848 occupant_type_id=self._static.occupant_type.empty).first() 872 occupant_type_id=self._static.occupant_type.empty).first()
849 occupant_id = empty.id 873 occupant_id = empty.id
850 else: 874 else:
851 (first_name, last_name) = self._get_first_last_name(info.name) 875 (first_name, last_name) = self._get_first_last_name(name)
852 records = self._detail_adapter.fetch_detail_by_type_data( 876 records = self._detail_adapter.fetch_detail_by_type_data(
853 self._static.detail_type.last_name, 877 self._static.detail_type.last_name,
854 last_name) 878 last_name)
@@ -865,12 +889,12 @@ class PopulateTables(object):
865 889
866 # last resort try to do a search 890 # last resort try to do a search
867 if not occupant_id: 891 if not occupant_id:
868 detail = self._search_adapter.search(info.name) 892 records = self._search_adapter.search(unicode(name))
869 if len(detail) == 1: 893 if records:
870 occupant_id = detail[0].occupant_id 894 occupant_id = records[0].occupant_id
871 895
872 if not occupant_id: 896 if not occupant_id:
873 self._log_obj.error(self.NO_OCCUPANT_DETAIL.format(info.name)) 897 self._log_obj.error(self.NO_OCCUPANT_DETAIL.format(name))
874 898
875 return occupant_id 899 return occupant_id
876 900
@@ -911,6 +935,8 @@ class PopulateTables(object):
911 output_ntwk_id_fileobj: 935 output_ntwk_id_fileobj:
912 output_ntwk_id_fileobj.write(self._get_ntwk_id_svg()) 936 output_ntwk_id_fileobj.write(self._get_ntwk_id_svg())
913 937
938 #TODO: eventually we need to generate ntwk_id_svg dynamically
939 #self._get_ntwk_id_svg()
914 self._get_name_label_svg() 940 self._get_name_label_svg()
915 941
916class Util(object): 942class Util(object):
@@ -948,8 +974,9 @@ class Util(object):
948class Process(object): 974class Process(object):
949 975
950 def __init__(self): 976 def __init__(self):
977 # structure svg finalized, no longer need to create structure SVG
978 # CreateStructureSVG(),
951 self._chain = [ 979 self._chain = [
952 CreateStructureSVG(),
953 ParseFloorPlanConferenceRoomXLS(), 980 ParseFloorPlanConferenceRoomXLS(),
954 PopulateTables(), 981 PopulateTables(),
955 ] 982 ]