def g_organize(): ''' adSource.objects.all().delete() for goog_cam in GoogleCampaign.objects.all(): goog_name = goog_cam.campaign_name category = adSource() category.provider = 'Google' category.name = goog_name for goog_key in GoogleKeyword.objects.all(): if goog_key.adgroup.campaign.campaign_name == goog_name: category.impressions = category.impressions + goog_key.impressions category.cost = round(category.cost,2) + round(goog_key.cost,2) category.clicks = category.clicks + goog_key.clicks category.cost = round(category.cost,2) if not category.impressions == 0: category.CTR = round(category.clicks * 100/category.impressions,2) category.CPM = round(category.cost * 1000 / category.impressions,2) if not category.clicks == 0: category.CPC = round(category.cost/category.clicks,2) category.save() ''' for goog_cam in GoogleCampaign.objects.all(): goog_name = goog_cam.campaign_name category = adSource() category.provider = 'Google' category.name = goog_name for goog_ad in goog_cam.googleadgroup_set.all(): for goog_key in goog_ad.googlekeyword_set.all(): #if goog_key.adgroup.campaign.campaign_name == goog_name: category.impressions = category.impressions + goog_key.impressions category.cost = round(category.cost, 2) + round( goog_key.cost, 2) category.clicks = category.clicks + goog_key.clicks category.cost = round(category.cost, 2) if not category.impressions == 0: category.CTR = round(category.clicks * 100 / category.impressions, 2) category.CPM = round(category.cost * 1000 / category.impressions, 2) if not category.clicks == 0: category.CPC = round(category.cost / category.clicks, 2) category.save()
def g_organize(): ''' adSource.objects.all().delete() for goog_cam in GoogleCampaign.objects.all(): goog_name = goog_cam.campaign_name category = adSource() category.provider = 'Google' category.name = goog_name for goog_key in GoogleKeyword.objects.all(): if goog_key.adgroup.campaign.campaign_name == goog_name: category.impressions = category.impressions + goog_key.impressions category.cost = round(category.cost,2) + round(goog_key.cost,2) category.clicks = category.clicks + goog_key.clicks category.cost = round(category.cost,2) if not category.impressions == 0: category.CTR = round(category.clicks * 100/category.impressions,2) category.CPM = round(category.cost * 1000 / category.impressions,2) if not category.clicks == 0: category.CPC = round(category.cost/category.clicks,2) category.save() ''' for goog_cam in GoogleCampaign.objects.all(): goog_name = goog_cam.campaign_name category = adSource() category.provider = 'Google' category.name = goog_name for goog_ad in goog_cam.googleadgroup_set.all(): for goog_key in goog_ad.googlekeyword_set.all(): #if goog_key.adgroup.campaign.campaign_name == goog_name: category.impressions = category.impressions + goog_key.impressions category.cost = round(category.cost,2) + round(goog_key.cost,2) category.clicks = category.clicks + goog_key.clicks category.cost = round(category.cost,2) if not category.impressions == 0: category.CTR = round(category.clicks * 100/category.impressions,2) category.CPM = round(category.cost * 1000 / category.impressions,2) if not category.clicks == 0: category.CPC = round(category.cost/category.clicks,2) category.save()
def fb_organize(): adSource.objects.all().delete() for fb_group in FacebookAccount.objects.all(): fb_name = fb_group.account_name category = adSource() category.provider = 'Facebook' category.name = fb_name for fb_cam in FacebookCampaign.objects.all(): if fb_cam.account.account_name == fb_name: category.impressions = category.impressions + fb_cam.impressions category.cost = category.cost + fb_cam.cost category.clicks = category.clicks + fb_cam.clicks category.cost = round(category.cost,2) if not category.impressions == 0: category.CTR = round(category.clicks * 100/category.impressions,2) category.CPM = round(category.cost * 1000 / category.impressions,2) if not category.clicks == 0: category.CPC = round(category.cost/category.clicks,2) category.save()
def fb_organize(): adSource.objects.all().delete() for fb_group in FacebookAccount.objects.all(): fb_name = fb_group.account_name category = adSource() category.provider = 'Facebook' category.name = fb_name for fb_cam in FacebookCampaign.objects.all(): if fb_cam.account.account_name == fb_name: category.impressions = category.impressions + fb_cam.impressions category.cost = category.cost + fb_cam.cost category.clicks = category.clicks + fb_cam.clicks category.cost = round(category.cost, 2) if not category.impressions == 0: category.CTR = round(category.clicks * 100 / category.impressions, 2) category.CPM = round(category.cost * 1000 / category.impressions, 2) if not category.clicks == 0: category.CPC = round(category.cost / category.clicks, 2) category.save()