示例#1
0
        /// <summary>
        /// Adds an experiment.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="campaignId">The campaign id.</param>
        /// <param name="adGroupId">The ad group id.</param>
        /// <param name="criterionId">The criterion id.</param>
        /// <returns>The experiment id.</returns>
        public long AddExperiment(AdWordsUser user, long campaignId, long adGroupId, long criterionId)
        {
            // Get the ExperimentService.
            ExperimentService experimentService =
                (ExperimentService)user.GetService(AdWordsService.v201406.ExperimentService);

            // Get the AdGroupService.
            AdGroupService adGroupService =
                (AdGroupService)user.GetService(AdWordsService.v201406.AdGroupService);

            // Get the AdGroupCriterionService.
            AdGroupCriterionService adGroupCriterionService =
                (AdGroupCriterionService)user.GetService(AdWordsService.v201406.AdGroupCriterionService);

            // Create the experiment.
            Experiment experiment = new Experiment();

            experiment.campaignId      = campaignId;
            experiment.name            = "Interplanetary Cruise #" + GetTimeStamp();
            experiment.queryPercentage = 10;
            experiment.startDateTime   = DateTime.Now.AddDays(1).ToString("yyyyMMdd HHmmss");

            // Create the operation.
            ExperimentOperation experimentOperation = new ExperimentOperation();

            experimentOperation.@operator = Operator.ADD;
            experimentOperation.operand   = experiment;

            // Add the experiment.
            ExperimentReturnValue experimentRetVal = experimentService.mutate(
                new ExperimentOperation[] { experimentOperation });

            return(experimentRetVal.value[0].id);
        }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="experimentId">Id of the experiment to be promoted.</param>
    public void Run(AdWordsUser user, long experimentId) {
      // Get the ExperimentService.
      ExperimentService experimentService =
          (ExperimentService) user.GetService(AdWordsService.v201509.ExperimentService);

      // Set experiment's status to PROMOTED.
      Experiment experiment = new Experiment();
      experiment.id = experimentId;
      experiment.status = ExperimentStatus.PROMOTED;

      // Create the operation.
      ExperimentOperation operation = new ExperimentOperation();
      operation.@operator = Operator.SET;
      operation.operand = experiment;

      try {
        // Update the experiment.
        ExperimentReturnValue retVal = experimentService.mutate(
            new ExperimentOperation[] {operation});

        // Display the results.
        if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
          Experiment promotedExperiment = retVal.value[0];
          Console.WriteLine("Experiment with name = \"{0}\" and id = \"{1}\" was promoted.\n",
              promotedExperiment.name, promotedExperiment.id);
        } else {
          Console.WriteLine("No experiments were promoted.");
        }
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to promote experiment.", e);
      }
    }
 public ExperimentOperationNode(string content)
 {
     ParentNode = null;
     Operation  = null;
     Content    = content;
     Operation  = new ExperimentOperation();
     ExperimentOperation.Name = content;
 }
示例#4
0
        public string AddExperiment()
        {
            string name       = Request["name"];
            string allowGrade = Request["allGrade"];
            string week       = Request["week"];
            string json       = new ExperimentOperation().AddExperiment(name, allowGrade, (int)ExpermentType.Experment, 10000, week);

            return("{\"back\":\"" + json + "\"}");
        }
示例#5
0
        public string EditExperiment()
        {
            string id         = Request["id"];
            string name       = Request["name"];
            string allowGrade = Request["allGrade"];
            string week       = Request["week"];
            string json       = new ExperimentOperation().EditExperiment(id, name, allowGrade, "10000", week);

            return("{\"back\":\"" + json + "\"}");
        }
示例#6
0
        public string AddCreat()
        {
            string name       = Request["name"];
            string allowGrade = Request["allGrade"];
            int    max        = Convert.ToInt32(Request["max"]);
            string week       = Request["week"];
            string json       = new ExperimentOperation().AddExperiment(name, allowGrade, (int)ExpermentType.Creativity, max, week);

            return("{\"back\":\"" + json + "\"}");
        }
示例#7
0
        public string CheckGrade(string id)
        {
            long sid    = (long)sc.GetStudentSession();
            bool result = new ExperimentOperation().CheckGrade(id, sid);

            if (result)
            {
                return("{\"back\":\"ok\"}");
            }
            return("{\"back\":\"对不起,该实验不对您开放.\"}");
        }
        public void SaveOperationTreeToFile(string fileName)
        {
            if (operationNodes.Count == 0)
            {
                return;
            }
            if (operationNodes[0] == null)
            {
                return;
            }
            Operation           operation           = GenerateOperationTree(operationNodes[0]);
            ExperimentOperation experimentOperation = operation as ExperimentOperation;

            if (experimentOperation != null)
            {
                ExperimentFlow.GetInstance().SaveOperationTreeToFile(experimentOperation, fileName);
            }
        }
        public void OpenOperationTreeFile(string fileName)
        {
            ExperimentOperation experimentOperation = ExperimentFlow.GetInstance().LoadOperationTreeFromFile(fileName);

            if (experimentOperation == null)
            {
                return;
            }

            OperationNode opeartionNode = GenerateOperationNodeTree(experimentOperation);

            ExpandOperationNode(opeartionNode);
            if (opeartionNode as ExperimentOperationNode != null)
            {
                operationNodes.Clear();
                operationNodes.Add(opeartionNode);
                opeartionNode.IsSelected = true;
            }
        }
示例#10
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="experimentId">Id of the experiment to be promoted.</param>
        public void Run(AdWordsUser user, long experimentId)
        {
            // Get the ExperimentService.
            ExperimentService experimentService =
                (ExperimentService)user.GetService(AdWordsService.v201607.ExperimentService);

            // Set experiment's status to PROMOTED.
            Experiment experiment = new Experiment();

            experiment.id     = experimentId;
            experiment.status = ExperimentStatus.PROMOTED;

            // Create the operation.
            ExperimentOperation operation = new ExperimentOperation();

            operation.@operator = Operator.SET;
            operation.operand   = experiment;

            try {
                // Update the experiment.
                ExperimentReturnValue retVal = experimentService.mutate(
                    new ExperimentOperation[] { operation });

                // Display the results.
                if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                {
                    Experiment promotedExperiment = retVal.value[0];
                    Console.WriteLine("Experiment with name = \"{0}\" and id = \"{1}\" was promoted.\n",
                                      promotedExperiment.name, promotedExperiment.id);
                }
                else
                {
                    Console.WriteLine("No experiments were promoted.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to promote experiment.", e);
            }
        }
示例#11
0
        public string RemoveExperiment(string id)
        {
            string json = new ExperimentOperation().RemoveExperiment(id);

            return("{\"back\":\"" + json + "\"}");
        }
示例#12
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which experiments are
        /// added.</param>
        /// <param name="adGroupId">Id of the ad group to which experiments are
        /// added.</param>
        /// <param name="criterionId">Id of the criterion for which experiments
        /// are added.</param>
        public void Run(AdWordsUser user, long campaignId, long adGroupId, long criterionId)
        {
            // Get the ExperimentService.
            ExperimentService experimentService =
                (ExperimentService)user.GetService(AdWordsService.v201607.ExperimentService);

            // Get the AdGroupService.
            AdGroupService adGroupService =
                (AdGroupService)user.GetService(AdWordsService.v201607.AdGroupService);

            // Get the AdGroupCriterionService.
            AdGroupCriterionService adGroupCriterionService =
                (AdGroupCriterionService)user.GetService(AdWordsService.v201607.AdGroupCriterionService);

            // Create the experiment.
            Experiment experiment = new Experiment();

            experiment.campaignId      = campaignId;
            experiment.name            = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString();
            experiment.queryPercentage = 10;
            experiment.startDateTime   = DateTime.Now.AddDays(1).ToString("yyyyMMdd HHmmss");

            // Optional: Set the end date.
            experiment.endDateTime = DateTime.Now.AddDays(30).ToString("yyyyMMdd HHmmss");

            // Optional: Set the status.
            experiment.status = ExperimentStatus.ENABLED;

            // Create the operation.
            ExperimentOperation experimentOperation = new ExperimentOperation();

            experimentOperation.@operator = Operator.ADD;
            experimentOperation.operand   = experiment;

            try {
                // Add the experiment.
                ExperimentReturnValue experimentRetVal = experimentService.mutate(
                    new ExperimentOperation[] { experimentOperation });

                // Display the results.
                if (experimentRetVal != null && experimentRetVal.value != null && experimentRetVal.value.
                    Length > 0)
                {
                    long experimentId = 0;

                    Experiment newExperiment = experimentRetVal.value[0];

                    Console.WriteLine("Experiment with name = \"{0}\" and id = \"{1}\" was added.\n",
                                      newExperiment.name, newExperiment.id);
                    experimentId = newExperiment.id;

                    // Set ad group for the experiment.
                    AdGroup adGroup = new AdGroup();
                    adGroup.id = adGroupId;

                    // Create experiment bid multiplier rule that will modify ad group bid
                    // for the experiment.
                    ManualCPCAdGroupExperimentBidMultipliers adGroupBidMultiplier =
                        new ManualCPCAdGroupExperimentBidMultipliers();
                    adGroupBidMultiplier.maxCpcMultiplier            = new BidMultiplier();
                    adGroupBidMultiplier.maxCpcMultiplier.multiplier = 1.5;

                    // Set experiment data to the ad group.
                    AdGroupExperimentData adGroupExperimentData = new AdGroupExperimentData();
                    adGroupExperimentData.experimentId             = experimentId;
                    adGroupExperimentData.experimentDeltaStatus    = ExperimentDeltaStatus.MODIFIED;
                    adGroupExperimentData.experimentBidMultipliers = adGroupBidMultiplier;

                    adGroup.experimentData = adGroupExperimentData;

                    // Create the operation.
                    AdGroupOperation adGroupOperation = new AdGroupOperation();
                    adGroupOperation.operand   = adGroup;
                    adGroupOperation.@operator = Operator.SET;

                    // Update the ad group.
                    AdGroupReturnValue adGroupRetVal = adGroupService.mutate(new AdGroupOperation[] {
                        adGroupOperation
                    });

                    // Display the results.
                    if (adGroupRetVal != null && adGroupRetVal.value != null &&
                        adGroupRetVal.value.Length > 0)
                    {
                        AdGroup updatedAdGroup = adGroupRetVal.value[0];
                        Console.WriteLine("Ad group with name = \"{0}\", id = \"{1}\" and status = \"{2}\" " +
                                          "was updated for the experiment.\n", updatedAdGroup.name, updatedAdGroup.id,
                                          updatedAdGroup.status);
                    }
                    else
                    {
                        Console.WriteLine("No ad groups were updated.");
                    }

                    // Set ad group criteria for the experiment.
                    Criterion criterion = new Criterion();
                    criterion.id = criterionId;

                    BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion();
                    adGroupCriterion.adGroupId = adGroupId;
                    adGroupCriterion.criterion = criterion;

                    // Create experiment bid multiplier rule that will modify criterion bid
                    // for the experiment.
                    ManualCPCAdGroupCriterionExperimentBidMultiplier bidMultiplier =
                        new ManualCPCAdGroupCriterionExperimentBidMultiplier();
                    bidMultiplier.maxCpcMultiplier            = new BidMultiplier();
                    bidMultiplier.maxCpcMultiplier.multiplier = 1.5;

                    // Set experiment data to the criterion.
                    BiddableAdGroupCriterionExperimentData adGroupCriterionExperimentData =
                        new BiddableAdGroupCriterionExperimentData();
                    adGroupCriterionExperimentData.experimentId            = experimentId;
                    adGroupCriterionExperimentData.experimentDeltaStatus   = ExperimentDeltaStatus.MODIFIED;
                    adGroupCriterionExperimentData.experimentBidMultiplier = bidMultiplier;

                    adGroupCriterion.experimentData = adGroupCriterionExperimentData;

                    // Create the operation.
                    AdGroupCriterionOperation adGroupCriterionOperation = new AdGroupCriterionOperation();
                    adGroupCriterionOperation.operand   = adGroupCriterion;
                    adGroupCriterionOperation.@operator = Operator.SET;

                    // Update the ad group criteria.
                    AdGroupCriterionReturnValue adGroupCriterionRetVal = adGroupCriterionService.mutate(
                        new AdGroupCriterionOperation[] { adGroupCriterionOperation });

                    // Display the results.
                    if (adGroupCriterionRetVal != null && adGroupCriterionRetVal.value != null &&
                        adGroupCriterionRetVal.value.Length > 0)
                    {
                        AdGroupCriterion updatedAdGroupCriterion = adGroupCriterionRetVal.value[0];
                        Console.WriteLine("Ad group criterion with ad group id = \"{0}\", criterion id = "
                                          + "\"{1}\" and type = \"{2}\" was updated for the experiment.\n",
                                          updatedAdGroupCriterion.adGroupId, updatedAdGroupCriterion.criterion.id,
                                          updatedAdGroupCriterion.criterion.CriterionType);
                    }
                    else
                    {
                        Console.WriteLine("No ad group criteria were updated.");
                    }
                }
                else
                {
                    Console.WriteLine("No experiments were added.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add experiment.", e);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign to which experiments are
        /// added.</param>
        /// <param name="adGroupId">Id of the ad group to which experiments are
        /// added.</param>
        /// <param name="criterionId">Id of the criterion for which experiments
        /// are added.</param>
        public void Run(AdWordsUser user, long campaignId, long adGroupId, long criterionId)
        {
            // Get the ExperimentService.
              ExperimentService experimentService =
              (ExperimentService) user.GetService(AdWordsService.v201601.ExperimentService);

              // Get the AdGroupService.
              AdGroupService adGroupService =
              (AdGroupService) user.GetService(AdWordsService.v201601.AdGroupService);

              // Get the AdGroupCriterionService.
              AdGroupCriterionService adGroupCriterionService =
              (AdGroupCriterionService) user.GetService(AdWordsService.v201601.AdGroupCriterionService);

              // Create the experiment.
              Experiment experiment = new Experiment();
              experiment.campaignId = campaignId;
              experiment.name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString();
              experiment.queryPercentage = 10;
              experiment.startDateTime = DateTime.Now.AddDays(1).ToString("yyyyMMdd HHmmss");

              // Optional: Set the end date.
              experiment.endDateTime = DateTime.Now.AddDays(30).ToString("yyyyMMdd HHmmss");

              // Optional: Set the status.
              experiment.status = ExperimentStatus.ENABLED;

              // Create the operation.
              ExperimentOperation experimentOperation = new ExperimentOperation();
              experimentOperation.@operator = Operator.ADD;
              experimentOperation.operand = experiment;

              try {
            // Add the experiment.
            ExperimentReturnValue experimentRetVal = experimentService.mutate(
            new ExperimentOperation[] {experimentOperation});

            // Display the results.
            if (experimentRetVal != null && experimentRetVal.value != null && experimentRetVal.value.
            Length > 0) {
              long experimentId = 0;

              Experiment newExperiment = experimentRetVal.value[0];

              Console.WriteLine("Experiment with name = \"{0}\" and id = \"{1}\" was added.\n",
              newExperiment.name, newExperiment.id);
              experimentId = newExperiment.id;

              // Set ad group for the experiment.
              AdGroup adGroup = new AdGroup();
              adGroup.id = adGroupId;

              // Create experiment bid multiplier rule that will modify ad group bid
              // for the experiment.
              ManualCPCAdGroupExperimentBidMultipliers adGroupBidMultiplier =
              new ManualCPCAdGroupExperimentBidMultipliers();
              adGroupBidMultiplier.maxCpcMultiplier = new BidMultiplier();
              adGroupBidMultiplier.maxCpcMultiplier.multiplier = 1.5;

              // Set experiment data to the ad group.
              AdGroupExperimentData adGroupExperimentData = new AdGroupExperimentData();
              adGroupExperimentData.experimentId = experimentId;
              adGroupExperimentData.experimentDeltaStatus = ExperimentDeltaStatus.MODIFIED;
              adGroupExperimentData.experimentBidMultipliers = adGroupBidMultiplier;

              adGroup.experimentData = adGroupExperimentData;

              // Create the operation.
              AdGroupOperation adGroupOperation = new AdGroupOperation();
              adGroupOperation.operand = adGroup;
              adGroupOperation.@operator = Operator.SET;

              // Update the ad group.
              AdGroupReturnValue adGroupRetVal = adGroupService.mutate(new AdGroupOperation[] {
              adGroupOperation});

              // Display the results.
              if (adGroupRetVal != null && adGroupRetVal.value != null &&
              adGroupRetVal.value.Length > 0) {
            AdGroup updatedAdGroup = adGroupRetVal.value[0];
            Console.WriteLine("Ad group with name = \"{0}\", id = \"{1}\" and status = \"{2}\" " +
                "was updated for the experiment.\n", updatedAdGroup.name, updatedAdGroup.id,
                updatedAdGroup.status);
              } else {
            Console.WriteLine("No ad groups were updated.");
              }

              // Set ad group criteria for the experiment.
              Criterion criterion = new Criterion();
              criterion.id = criterionId;

              BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion();
              adGroupCriterion.adGroupId = adGroupId;
              adGroupCriterion.criterion = criterion;

              // Create experiment bid multiplier rule that will modify criterion bid
              // for the experiment.
              ManualCPCAdGroupCriterionExperimentBidMultiplier bidMultiplier =
              new ManualCPCAdGroupCriterionExperimentBidMultiplier();
              bidMultiplier.maxCpcMultiplier = new BidMultiplier();
              bidMultiplier.maxCpcMultiplier.multiplier = 1.5;

              // Set experiment data to the criterion.
              BiddableAdGroupCriterionExperimentData adGroupCriterionExperimentData =
              new BiddableAdGroupCriterionExperimentData();
              adGroupCriterionExperimentData.experimentId = experimentId;
              adGroupCriterionExperimentData.experimentDeltaStatus = ExperimentDeltaStatus.MODIFIED;
              adGroupCriterionExperimentData.experimentBidMultiplier = bidMultiplier;

              adGroupCriterion.experimentData = adGroupCriterionExperimentData;

              // Create the operation.
              AdGroupCriterionOperation adGroupCriterionOperation = new AdGroupCriterionOperation();
              adGroupCriterionOperation.operand = adGroupCriterion;
              adGroupCriterionOperation.@operator = Operator.SET;

              // Update the ad group criteria.
              AdGroupCriterionReturnValue adGroupCriterionRetVal = adGroupCriterionService.mutate(
              new AdGroupCriterionOperation[] {adGroupCriterionOperation});

              // Display the results.
              if (adGroupCriterionRetVal != null && adGroupCriterionRetVal.value != null &&
              adGroupCriterionRetVal.value.Length > 0) {
            AdGroupCriterion updatedAdGroupCriterion = adGroupCriterionRetVal.value[0];
            Console.WriteLine("Ad group criterion with ad group id = \"{0}\", criterion id = "
                + "\"{1}\" and type = \"{2}\" was updated for the experiment.\n",
                updatedAdGroupCriterion.adGroupId, updatedAdGroupCriterion.criterion.id,
                updatedAdGroupCriterion.criterion.CriterionType);
              } else {
            Console.WriteLine("No ad group criteria were updated.");
              }
            } else {
              Console.WriteLine("No experiments were added.");
            }
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to add experiment.", e);
              }
        }
 public ExperimentOperationNode(ExperimentOperation experimentOperation)
 {
     Operation  = experimentOperation;
     ParentNode = null;
 }
示例#15
0
        /// <summary>
        /// Adds an experiment.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="campaignId">The campaign id.</param>
        /// <param name="adGroupId">The ad group id.</param>
        /// <param name="criterionId">The criterion id.</param>
        /// <returns>The experiment id.</returns>
        public long AddExperiment(AdWordsUser user, long campaignId, long adGroupId, long criterionId)
        {
            // Get the ExperimentService.
              ExperimentService experimentService =
              (ExperimentService) user.GetService(AdWordsService.v201601.ExperimentService);

              // Get the AdGroupService.
              AdGroupService adGroupService =
              (AdGroupService) user.GetService(AdWordsService.v201601.AdGroupService);

              // Get the AdGroupCriterionService.
              AdGroupCriterionService adGroupCriterionService =
              (AdGroupCriterionService) user.GetService(AdWordsService.v201601.AdGroupCriterionService);

              // Create the experiment.
              Experiment experiment = new Experiment();
              experiment.campaignId = campaignId;
              experiment.name = "Interplanetary Cruise #" + GetTimeStamp();
              experiment.queryPercentage = 10;
              experiment.startDateTime = DateTime.Now.AddDays(1).ToString("yyyyMMdd HHmmss");

              // Create the operation.
              ExperimentOperation experimentOperation = new ExperimentOperation();
              experimentOperation.@operator = Operator.ADD;
              experimentOperation.operand = experiment;

              // Add the experiment.
              ExperimentReturnValue experimentRetVal = experimentService.mutate(
              new ExperimentOperation[] { experimentOperation });

              return experimentRetVal.value[0].id;
        }