当前位置: 首页>>代码示例>>Python>>正文


Python GeneralMethods.group_items_by方法代码示例

本文整理汇总了Python中library.classes.GeneralMethods.group_items_by方法的典型用法代码示例。如果您正苦于以下问题:Python GeneralMethods.group_items_by方法的具体用法?Python GeneralMethods.group_items_by怎么用?Python GeneralMethods.group_items_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在library.classes.GeneralMethods的用法示例。


在下文中一共展示了GeneralMethods.group_items_by方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mapper

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
 def mapper(self, key, hashtag_object):
     hashtag = hashtag_object['hashtag']
     ltuo_occ_time_and_occ_location = hashtag_object['ltuo_occ_time_and_occ_location']
     if ltuo_occ_time_and_occ_location:
         ltuo_intvl_time_and_occ_location = [(
                                            GeneralMethods.approximateEpoch(occ_time, TIME_UNIT_IN_SECONDS),
                                            occ_location
                                             ) 
                                           for occ_time, occ_location in ltuo_occ_time_and_occ_location]
         points = [UTMConverter.getLatLongUTMIdInLatLongForm(loc) for _, loc in ltuo_occ_time_and_occ_location]
         ltuo_intvl_time_and_items =\
                                 GeneralMethods.group_items_by(ltuo_intvl_time_and_occ_location, key=itemgetter(0))
         ltuo_intvl_time_and_items.sort(key=itemgetter(0))
         first_time = ltuo_intvl_time_and_items[0][0]
         ltuo_iid_and_occ_count = map(lambda (t, it): ((t-first_time)/TIME_UNIT_IN_SECONDS, len(it)), ltuo_intvl_time_and_items)
         ltuo_location_and_items =\
                                 GeneralMethods.group_items_by(ltuo_intvl_time_and_occ_location, key=itemgetter(1))
         mf_location_to_occ_count = dict(map(lambda (l, it): (l, len(it)), ltuo_location_and_items))
         spatial_metrics = {
                              'hashtag': hashtag,
                              'num_of_occurrenes': len(ltuo_occ_time_and_occ_location),
                              'peak_iid': max(ltuo_iid_and_occ_count, key=itemgetter(1))[0],
                              'focus': focus(mf_location_to_occ_count),
                              'entropy': entropy(mf_location_to_occ_count, as_bits=False),
                              'spread': getRadiusOfGyration(points)
                          }
         yield hashtag, spatial_metrics
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:29,代码来源:mr_analysis_nov_12.py

示例2: reducer

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
 def reducer(self, location, it_performance_values):
     performance_values = list(chain(*it_performance_values))
     performance_summary = defaultdict(list)
     for prediction_method, pvs_for_prediction_method in \
                             GeneralMethods.group_items_by(performance_values, key=itemgetter('prediction_method')):
         for metric, pvs_for_prediction_method_and_metric in \
                         GeneralMethods.group_items_by(pvs_for_prediction_method, key=itemgetter('metric')):
             performance_summary[metric].append([
                                                 prediction_method,
                                                 pvs_for_prediction_method_and_metric[0]['metric_value']
                                         ])
     yield '', dict(location=location, performance_summary=performance_summary)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:14,代码来源:mr_predict_hashtags_for_locations.py

示例3: reducer

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
 def reducer(self, location, it_ltuo_occ_time_and_count):
     ltuo_occ_time_and_count = [(t, sum(zip(*l)[1]))
                                 for t, l in GeneralMethods.group_items_by(
                                                                           list(chain(*it_ltuo_occ_time_and_count)),
                                                                           key=itemgetter(0)
                                                                           )
                                ]
     yield location, {'location': location, 'ltuo_occ_time_and_count': ltuo_occ_time_and_count}
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:10,代码来源:mr_analysis_nov_12.py

示例4: get_components_by_clustering

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
 def get_components_by_clustering(self, graph):
     _, ltuo_node_and_cluster_id = clusterUsingAffinityPropagation(graph)
     ltuo_cluster_id_and_ltuo_node_id_and_cluster_id = GeneralMethods.group_items_by(
         ltuo_node_and_cluster_id, itemgetter(1)
     )
     ltuo_cluster_id_and_nodes = map(
         lambda (c_i, l_n_c): (c_i, zip(*l_n_c)[0]), ltuo_cluster_id_and_ltuo_node_id_and_cluster_id
     )
     return zip(*ltuo_cluster_id_and_nodes)[1]
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:11,代码来源:mr_analysis.py

示例5: entropy_examples

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
 def entropy_examples():
     output_file_format = fld_data_analysis_results%GeneralMethods.get_method_id()+'/%s.png'
     data = [d for d in FileIO.iterateJsonFromFile(f_hashtag_spatial_metrics, remove_params_dict=True)]
     ltuo_hashtag_and_num_of_occurrences_and_entropy =\
                                                 map(
                                                     itemgetter('hashtag', 'num_of_occurrenes', 'entropy'),
                                                     data
                                                     )
     ltuo_hashtag_and_num_of_occurrences_and_entropy =\
                                                 map(
                                                     lambda (h, n, e): (h, n, round(e,0)),
                                                     ltuo_hashtag_and_num_of_occurrences_and_entropy
                                                     )
     for entropy, entropy_data in \
             GeneralMethods.group_items_by(ltuo_hashtag_and_num_of_occurrences_and_entropy, itemgetter(2)):
         entropy_data.sort(key=itemgetter(1))
         hashtags = map(itemgetter(0), entropy_data)
         print entropy, len(entropy_data), hashtags[:25]
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:20,代码来源:plots_nov_12.py

示例6: mapper1

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
 def mapper1(self, key, hashtag_object):
     if False: yield
     hashtag = hashtag_object['hashtag']
     ltuo_occ_time_and_occ_location = hashtag_object['ltuo_occ_time_and_occ_location']
     ltuo_location_and_items = GeneralMethods.group_items_by(ltuo_occ_time_and_occ_location, key=itemgetter(1))
     ltuo_location_and_occurrence_time =\
                         [(location, min(items, key=itemgetter(0))[0])for location, items in ltuo_location_and_items]
     ltuo_location_and_occurrence_time = [(
                                           location, 
                                           GeneralMethods.approximateEpoch(occurrence_time, TIME_UNIT_IN_SECONDS)
                                           ) 
                                          for location, occurrence_time in ltuo_location_and_occurrence_time]
     if ltuo_location_and_occurrence_time:
         occurrence_times = filter_outliers(zip(*ltuo_location_and_occurrence_time)[1])
         ltuo_location_and_occurrence_time =\
                                         filter(lambda (l, o): o in occurrence_times, ltuo_location_and_occurrence_time)
         for location, occurrence_time in ltuo_location_and_occurrence_time:
             self.mf_location_to_ltuo_hashtag_and_min_occ_time[location].append([hashtag, occurrence_time])
             for neighbor_location, _ in ltuo_location_and_occurrence_time:
                 if location!=neighbor_location:
                     self.mf_location_to_neighbor_locations[location].add(neighbor_location)
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:23,代码来源:mr_analysis_nov_12.py

示例7: example_for_caverlee

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
    def example_for_caverlee():
#        valid_locations = ['18T_585E_4512N', '18T_587E_4514N']
        mf_lid_to_location = dict([
                                   ('18T_585E_4512N', 'Times Square'),
                                   ('18T_587E_4514N', 'Central Park'),
                                   ('18T_584E_4511N', 'Penn Station'),
                                   ('18T_585E_4511N', 'Empire State Building'),
                                   ])
        output_file_format = fld_data_analysis_results%GeneralMethods.get_method_id()+'/%s.png'
        subplot_num = 221
#        plt.figure(num=None, figsize=(6,3))
        for data in FileIO.iterateJsonFromFile(f_example_for_caverlee, remove_params_dict=True):
            location = data['location']
            if location in mf_lid_to_location:
                td = timedelta(hours=-5)
                ltuo_occ_time_and_count = data['ltuo_occ_time_and_count']
                ltuo_occ_time_and_count.sort(key=itemgetter(0))
                occ_times, counts = zip(*ltuo_occ_time_and_count)
                occ_times = map(datetime.fromtimestamp, occ_times)
                occ_times = map(lambda d: d+td, occ_times)
                occ_hours = map(lambda d: d.hour, occ_times)
                ltuo_occ_hour_and_count = zip(occ_hours, counts)
                ltuo_occ_hour_and_count = [(h, sum(zip(*h_c)[1])) for h, h_c in
                                            GeneralMethods.group_items_by(ltuo_occ_hour_and_count, key=itemgetter(0))]
                occ_hours, counts = zip(*ltuo_occ_hour_and_count)
                total_counts = sum(counts)+0.0
                counts = map(lambda c: c/total_counts, counts)
                plt.subplot(subplot_num)
#                plt.subplots_adjust(bottom=0.2, top=0.9)
                subplot_num+=1
                plt.plot(occ_hours, counts, color='#EA00FF', lw=1)
                plt.fill_between(occ_hours, counts, color='#EA00FF', alpha=0.25)
#                plt.ylabel('% of tweets')
                plt.xlabel('Time of day')
                plt.xlim(xmax=23)
                plt.ylim(ymax=0.09)
                plot_anchored_text(mf_lid_to_location[location], loc=2)
                plt.grid(True)
#                savefig(output_file_format%mf_lid_to_location[location].replace(' ', '_'))
        savefig(output_file_format%'ny_locations')
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:42,代码来源:plots_nov_12.py

示例8: mapper_final

# 需要导入模块: from library.classes import GeneralMethods [as 别名]
# 或者: from library.classes.GeneralMethods import group_items_by [as 别名]
 def mapper_final(self):
     for location, occ_times in self.mf_location_to_occ_times.iteritems():
         ltuo_occ_time_and_count = [(t, len(l))
                                             for t, l in GeneralMethods.group_items_by(occ_times, lambda item: item)]
         yield location, ltuo_occ_time_and_count
开发者ID:kykamath,项目名称:hashtags_and_geo,代码行数:7,代码来源:mr_analysis_nov_12.py


注:本文中的library.classes.GeneralMethods.group_items_by方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。