def get_peak_trends(post_ids, trend_values, sharecount_list, category_list, peak_list): trend = [] ids = [] shares = [] category = [] peaks = [] for i, item in enumerate(trend_values): if item != '': a = map(int, item.split(',')) if sharecount_list[i] > 300000: continue trend.append(np.array(a)) ids.append(post_ids[i]) shares.append(sharecount_list[i]) category.append(category_list[i]) peaks.append(peak_list[i]) colors = [] total_peak_trends = 0 for i, item in enumerate(trend): # if item[15] == 100: if len(item) == 31 and 100 in item[13:18]: #print(ids[i], shares[i], category[i]) total_peak_trends += 1 colors.append('r') else : colors.append('g') ''' sql = """ UPDATE trends_manual SET peak_at_publish = %s WHERE post_id = %s """ cursor.execute(sql, [1, ids[i]]) ''' # conn.commit() print("num of peak trends : %d"%total_peak_trends) mean_trend = [] for item in trend: mean_trend.append(np.mean(item[0:15])) markers = get_marker(category) legends = get_legends(category) Scatter = ScatterPlot() Scatter.set_log(True) Scatter.set_data(mean_trend, shares, colors, markers, legends) Scatter.set_ylim(100000) Scatter.save_image('../image/trends_sharecount_scatter.png')
def _scatter_plot_2_default(self): """ Returns the default value for the second scatter plot. """ result = ScatterPlot(index=self.scatter_plot_1.index) result.value.description += ' 2' result.value.optional = True return result
def _scatter_plot_1_default(self): """ Returns the default value for the first scatter plot. """ result = ScatterPlot() result.index.description = 'Shared Plot Index' result.value.description += ' 1' return result
def _scatter_plots_default(self): """ Returns the default value for the scatter plots list. """ plots = [] for i in range(self.rows * self.columns): plots.append(ScatterPlot()) self._update_plots(plots) return plots
def _grid_changed(self): """ Handles the grid size being changed. """ n = self.rows * self.columns plots = self.scatter_plots if n < len(plots): self.scatter_plots = plots[:n] else: for j in range(len(plots), n): plots.append(ScatterPlot()) self._update_plots(plots) self.template_mutated = True