示例#1
0
 public int Run3(int time, string _pathin, ref Result2 result)
 {
     Stop3();
     if(GetImage3(_pathin))
     {
         try
         {
             myJobManager3.Run())
             System.Threading.Thread.Sleep(time);
         }
         catch
         {
             return 2;
         }
         if(GetResult3(ref result))
         {
             Stop3();
             return 0;
         }
         else
         {
             return 3;
         }
     }
     else
     {
         return 1;
     }
     return 4;
 }
示例#2
0
    /*
     * Determina la localidad donde los homicidios son mas frecuentes y cuantos
     * homicidios en total ocurrieron ahi.  En caso de empates, puedes devolver
     * cualquiera de las localidades que tienen la misma maxima cantidad de
     * homicidios.
     */
    static Result2 MostFrequentLocation(Event[] events)
    {
        // TODO: implementar algoritmo que resuelva este problema e indique cual
        //       es su complejidad average case
        // Valor: 3 puntos
        // Complejidad esperada: mejor que O(N^2)


        Dictionary <string, int> CriminalRecord = new Dictionary <string, int>();
        int    KillCount   = 0;
        string WorstBarrio = string.Empty;

        for (int i = 0; i < events.Length; i++)                                      // itera N veces donde N es el tamaño del arreglo
        {
            if (CriminalRecord.TryGetValue(events[i].location, out int count))       // En caso de ser True , ambos el Remove y el Add del dictionary son O(1) al igual que el TryGetValue.
            {
                count++;
                CriminalRecord.Remove(events[i].location);
                CriminalRecord.Add(events[i].location, count);
                if (count >= KillCount)
                {
                    KillCount   = count;
                    WorstBarrio = events[i].location;
                }
            }
            else
            {
                CriminalRecord.Add(events[i].location, 1);                           // Otro Add que seria O(1)
            }
        }

        Result2 result = new Result2(WorstBarrio, KillCount);                        // Asi que mi Complejidad Average Case es O(N);

        return(result);
    }
示例#3
0
 private bool GetResult2(ref Result2 result)
 {
     if (null == myJobManager2)
     {
         return false;
     }
     ICogRecord tmpRecord;
     ICogRecord topRecord;
     try
     {
         topRecord = myJobManager2.UserResult();
         if (null == topRecord)
         {
             return false;
         }
         if (null != cogRecordDisplay2)
         {
             tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"];
             tmpRecord = tmpRecord.SubRecords["LastRun"];
             tmpRecord = tmpRecord.SubRecords["CogFixtureTool1.OutputImage"];
             if (null != tmpRecord.Content)
             {
                 cogRecordDisplay2.Record = tmpRecord;
             }
             cogRecordDisplay2.AutoFit = true;
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
示例#4
0
    /*
     * Determina la localidad donde los homicidios son mas frecuentes y cuantos
     * homicidios en total ocurrieron ahi.  En caso de empates, puedes devolver
     * cualquiera de las localidades que tienen la misma maxima cantidad de
     * homicidios.
     */
    static Result2 MostFrequentLocation(Event[] events)
    {
        // TODO: implementar algoritmo que resuelva este problema e indique cual
        //       es su complejidad average case
        // Valor: 3 puntos
        // Complejidad esperada: mejor que O(N^2)


        // START

        // Documentacion : TrygetValue  https://docs.microsoft.com/es-es/dotnet/api/system.collections.generic.dictionary-2.trygetvalue?view=netframework-4.7.2

        int count = 0;                                                 // Costante

        Dictionary <string, int> ord = new Dictionary <string, int>(); // Crearlo es constante


        Stack <Result2> stack = new Stack <Result2>();           // Crearlo es constante

        foreach (var obj in events)                              // Lineal
        {
            bool flag = false;                                   // O(1)
            flag = ord.TryGetValue(obj.location, out int radio); // Constante avg
            if (flag)
            {
                ord.TryGetValue(obj.location, out int radio2);       // O(1) AVG
                radio2++;                                            // O(1) avg
                ord.Remove(obj.location);                            // O(1) avg
                ord.Add(obj.location, radio2);                       // O(1) avg

                if (radio2 > count)                                  //  O(1)
                {
                    count = radio2;                                  //  O(1)
                    Result2 res2 = new Result2(obj.location, count); // Constante
                    if (stack.Count != 0)                            // O(1)
                    {
                        stack.Pop();                                 //  O(1)
                    }
                    stack.Push(res2);                                //  O(1)
                }
            }
            else
            {
                Result2 res2 = new Result2(obj.location, 1); // O(1)
                ord.Add(obj.location, 1);                    // O(1) AVG
            }

            if (stack.Count == 0)
            {
                var     dato = events[0];                     // O(1)
                Result2 res  = new Result2(dato.location, 1); // O(1)
                stack.Push(res);                              // O(1)
            }
        }
        // END

        return(stack.Pop()); // O(1)

        // Mi complejidad esperada en avg case es O(N) y worst case es O(N^2)
    }
示例#5
0
        public async Task <IActionResult> Edit(int id, [Bind("id,name,short_description,long_description,icon_url,language,created_at,updated_at")] Result2 result2)
        {
            if (id != result2.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(result2);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Result2Exists(result2.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(result2));
        }
示例#6
0
        public void Result2_OnSuccessMapTest()
        {
            var result = Result2 <Order, string> .Succeeded(new Order());

            var result2 = result.OnSuccess(order => new Customer());

            result2.IsSuccess.Should().BeTrue();
            result2.SuccessResult.GetType().Should().Be(typeof(Customer));
        }
示例#7
0
        public void Result2_GivenAFailure_WhenOnFailureBind_BindToOtherFailure()
        {
            var result = Result2 <Order, string> .Failed("error");

            var result2 = result.ConvertFailure(e => Result2 <Order, int> .Failed(e.Length));

            result2.IsFailure.Should().BeTrue();
            result2.FailureResult.Should().Be(5);
            result2.SuccessResult.Should().BeNull();
        }
示例#8
0
        public void Result2_OnFailureActionTest()
        {
            string output = null;
            var    result = Result2 <Order, string> .Failed("error");

            var result2 = result.OnFailure(e => { output = e.ToUpper(); });

            result2.IsFailure.Should().BeTrue();
            output.Should().Be("ERROR");
        }
示例#9
0
        public void Result2_GivenOnSuccesMap_WhenIsFailure_ExpectNoOperation()
        {
            var result = Result2 <Order, string> .Failed("error");

            var result2 = result.OnSuccess(order => new Customer());

            result2.IsSuccess.Should().BeFalse();
            result2.SuccessResult.Should().BeNull();
            result2.FailureResult.Should().Be("error");
        }
示例#10
0
        public void Result2_GivenAFailure_WhenOnFailureMap_ExpectCorrectedSuccess()
        {
            var result = Result2 <Order, string> .Failed("error");

            var result2 = result.OnFailure(e => new Order());

            result2.IsSuccess.Should().BeTrue();
            result2.SuccessResult.GetType().Should().Be(typeof(Order));
            result2.FailureResult.Should().BeNull();
        }
示例#11
0
        public async Task <IActionResult> Create([Bind("id,name,short_description,long_description,icon_url,language,created_at,updated_at")] Result2 result2)
        {
            if (ModelState.IsValid)
            {
                _context.Add(result2);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(result2));
        }
示例#12
0
 private Result2 <Customer, string[]> GetCustomerResult(int customerId)
 {
     try
     {
         return(Result2 <Customer, string[]> .Succeeded(Repository.GetCustomer(customerId)));
     }
     catch (Exception ex)
     {
         return(Result2 <Customer, string[]> .Failed(new[] { ex.Message }));
     }
 }
示例#13
0
 private Result2 <Product, string[]> GetProductResult(int productId)
 {
     try
     {
         return(Result2 <Product, string[]> .Succeeded(Repository.GetProduct(productId)));
     }
     catch (Exception ex)
     {
         return(Result2 <Product, string[]> .Failed(new[] { ex.Message }));
     }
 }
示例#14
0
        // eigenlijk zou ik hier Result2<OrderUpdateResult,OrderUpdateResult> willen teruggeven.
        // maar dat kan niet omdat een failure string[] niet geconverteerd kan worden naar een OrderUpdateResult
        private Result2 <OrderUpdateResult, string[]> AddProductToCustomerOrder(
            Order order,
            Customer customer,
            Product product)
        {
            if ((order.TotalOrderAmount() + product.Price) > customer.OrderLimit)
            {
                return(Result2 <OrderUpdateResult, string[]> .Succeeded(OrderUpdateResult.ExceedLimit));
            }

            order.AddProduct(product);
            return(Result2 <OrderUpdateResult, string[]> .Succeeded(OrderUpdateResult.OK));
        }
示例#15
0
        public void Result2_OnSuccessActionTest()
        {
            Order orderResult = null;
            var   result      = Result2 <Order, string> .Succeeded(new Order()
            {
                Id = 123
            });

            var result2 = result.OnSuccess(order => { orderResult = order; });

            result2.IsSuccess.Should().BeTrue();
            result2.SuccessResult.GetType().Should().Be(typeof(Order));
            orderResult.Id.Should().Be(123);
        }
示例#16
0
        private Result2 <OrderUpdateResult, string[]> UpdateModifiedOrder(Order order)
        {
            try
            {
                if (Repository.UpdateOrder(order))
                {
                    return(Result2 <OrderUpdateResult, string[]> .Succeeded(OrderUpdateResult.OK));
                }

                return(Result2 <OrderUpdateResult, string[]> .Failed(new[] { "Failed to Update Order" }));
            }
            catch (Exception e)
            {
                return(Result2 <OrderUpdateResult, string[]> .Failed(new[] { e.Message }));
            }
        }
示例#17
0
        private Result2 <Order, string[]> GetOrderResult(int orderId)
        {
            try
            {
                Order order = Repository.GetOrder(orderId);
                if (order != null)
                {
                    return(Result2 <Order, string[]> .Succeeded(order));
                }

                return(Result2 <Order, string[]> .Failed(new [] { $"Order with id {orderId} does not exist." }));
            }
            catch (Exception ex)
            {
                return(Result2 <Order, string[]> .Failed(new[] { ex.Message }));
            }
        }
示例#18
0
        public void Result2_GivenTwoDifferentFailureType_ConvertToOtherFailure()
        {
            // The code below will not return a Result2<Customer, int> on failure
            // var result =
            //    Result2<Order, string>.Failed("error")
            //        .OnSuccess(o => Result2<Customer, int>.Succeeded(new Customer()));
            //
            // result.FailureResult.Should().Be(-1)
            // will not compile unless a ConvertFailure is added to the chain.
            //
            var result =
                Result2 <Order, string> .Failed("error")
                .ConvertFailure(e => Result2 <Order, int> .Failed(-1))    // bind
                .OnSuccess(o => Result2 <Customer, int> .Succeeded(new Customer()));

            result.IsFailure.Should().BeTrue();
            result.FailureResult.Should().Be(-1);
        }
示例#19
0
 private bool GetResult2(ref Result2 result)
 {
     if (null == myJobManager2)
     {
         return false;
     }
     ICogRecord tmpRecord;
     ICogRecord topRecord;
     try
     {
         topRecord = myJobManager2.UserResult();
         if (null == topRecord)
         {
             return false;
         }
         tmpRecord = topRecord.SubRecords[@"QRCode"];
         if (null != tmpRecord.Content) 
         {
             result.ResultQRCode = (string)tmpRecord.Content;
         }
         if (null != cogRecordDisplay2)
         {
             tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"];
             tmpRecord = tmpRecord.SubRecords["LastRun"];
             tmpRecord = tmpRecord.SubRecords["CogImageFileTool1.OutputImage"];
             if (null != tmpRecord.Content)
             {
                 cogRecordDisplay2.Record = tmpRecord;
             }
             cogRecordDisplay2.Fit(true);
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
示例#20
0
 private Result2 <bool, string[]> BoolSuccess()
 {
     return(Result2 <bool, string[]> .Succeeded(true));
 }
示例#21
0
 private Result2 <bool, string[]> BoolFailure()
 {
     return(Result2 <bool, string[]> .Failed(new [] { "error" }));
 }
示例#22
0
 private Result2 <int, string[]> IntSuccess()
 {
     return(Result2 <int, string[]> .Succeeded(123));
 }
示例#23
0
 private Result2 <string, string[]> StringSuccess()
 {
     return(Result2 <string, string[]> .Succeeded("foo"));
 }
示例#24
0
 private Result2 <string, string[]> StringFailure()
 {
     return(Result2 <string, string[]> .Failed(new[] { "error" }));
 }
示例#25
0
 private void Button17_Click(object sender, EventArgs e)
 {
     Result2.Clear();
 }
示例#26
0
        private void CollectNew()
        {
            var mdbfiles  = FolderExtensions.GetFiles(SourceFolder, "*.mdb");
            var codefiles = FolderExtensions.GetFiles(SourceFolder, "*.xls");

            OutputMessage("成功获取数据路径下的所有矢量文件和单位代码表文件");

            var ranges = new Dictionary <CollectTable, List <ExcelField> >();

            foreach (var name in CollectTables)
            {
                var table = Arguments.CollectTableDict.Keys.FirstOrDefault(e => e.Name.ToLower() == name.ToLower());
                if (table != null)
                {
                    ranges.Add(table, Arguments.CollectTableDict[table]);
                }
            }

            OutputMessage("成功获取需要生成的表格类型信息");

            var tools = new List <GatherTool>();

            foreach (var shi in CollectXZQ)
            {
                if (shi.Children != null)
                {
                    foreach (var quxian in shi.Children)
                    {
                        var code = codefiles.FirstOrDefault(e => e.XZQDM.ToLower() == quxian.XZCDM.ToLower() && e.XZQMC.ToLower() == quxian.XZCMC.ToLower());
                        var mdb  = mdbfiles.FirstOrDefault(e => e.XZQDM.ToLower() == quxian.XZCDM.ToLower() && e.XZQMC.ToLower() == quxian.XZCMC.ToLower());
                        if (mdb != null)
                        {
                            tools.Add(new GatherTool {
                                Dict = ranges, MdbFile = mdb.FullName, XZQDM = quxian.XZCDM, XZQMC = quxian.XZCMC
                            });
                        }
                    }
                }
            }
            OutputMessage("成功创建每个区县获取工具");
            foreach (var tool in tools)
            {
                OutputMessage(string.Format("正在读取行政区代码【{0}】行政区名称【{1}】的矢量数据,请稍等", tool.XZQDM, tool.XZQMC));
                Console.WriteLine(tool.XZQMC);
                tool.Program();
                var output = tool.Collect2;
                _result2.AddRange(output);
                OutputMessage(string.Format("完成对行政区代码【{0}】行政区名称【{1}】的数据查询操作", tool.XZQDM, tool.XZQMC));
            }
            OutputMessage(string.Format("完成所有数据信息的读取,共获取{0}个区县数据信息", tools.Count));
            var writes = new List <WriteCollectTool>();

            foreach (var tableInfo in ranges)
            {
                var collects = Result2.Where(e => e.Table.Name == tableInfo.Key.Name).ToList();
                writes.Add(new WriteCollectTool {
                    CollectExcelTypes = CollectExcelTypes, SaveFolder = SaveFolder, Fields = tableInfo.Value, Collect2 = collects, CollectTable = tableInfo.Key, CollectXZQ = CollectXZQ
                });
            }

            foreach (var tool in writes)
            {
                tool.Program();
            }
            //Parallel.ForEach(writes, tool =>
            //{
            //    tool.Program();
            //});
            OutputMessage("成功保存文件,请在保存路径中查看文件!");
        }
    /*
     * Determina la localidad donde los homicidios son mas frecuentes y cuantos
     * homicidios en total ocurrieron ahi.  En caso de empates, puedes devolver
     * cualquiera de las localidades que tienen la misma maxima cantidad de
     * homicidios.
     */
    static Result2 MostFrequentLocation(Event[] events)
    {
        // TODO: implementar algoritmo que resuelva este problema e indique cual
        //       es su complejidad average case
        // Valor: 3 puntos
        // Complejidad esperada: mejor que O(N^2)

        // Documentacion de Dictionary : https://docs.microsoft.com/es-es/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.7.2
        // Documentacion : TrygetValue  https://docs.microsoft.com/es-es/dotnet/api/system.collections.generic.dictionary-2.trygetvalue?view=netframework-4.7.2
        // Operaciones utilizadas de Dictionary: Trygetvalue, remove son O(1), add O(1) AVG case
        // El Stack solo contiene un dato en la pila por lo tanto las operaciones Add y Pop se mantienen contante

        if (events.Length == 0)
        {
            throw new InvalidOperationException();                     // O(1)
        }
        int count = 0;                                                 //  O(1)

        Dictionary <string, int> ord = new Dictionary <string, int>(); // Crearlo es constante

        Stack <Result2> stack = new Stack <Result2>();                 // Crearlo es constante

        foreach (var obj in events)                                    // O(N)
        {
            if (obj.day < 0)                                           // Si el numero es negativo simplemente lo saltara porque no existen dias negativos
            {
                continue;                                              // O(1)
            }
            bool flag = false;                                         // O(1)
            flag = ord.TryGetValue(obj.location, out int radio);       // O(1)

            if (flag)
            {
                ord.TryGetValue(obj.location, out int radio2); // O(1)
                radio2++;                                      // O(1) avg
                ord.Remove(obj.location);                      // O(1)
                ord.Add(obj.location, radio2);                 // O(1)

                if (radio2 > count)
                {
                    count = radio2;                                  //  O(1)
                    Result2 res2 = new Result2(obj.location, count); //  O(1)
                    if (stack.Count != 0)                            // O(1)
                    {
                        stack.Pop();                                 //  O(1)
                    }
                    stack.Push(res2);                                //  O(1)
                }
            }
            else
            {
                Result2 res2 = new Result2(obj.location, 1); // O(1)
                ord.Add(obj.location, 1);                    // O(1)
            }
        }

        if (stack.Count == 0)
        {
            var     dato = events[0];                     // O(1)
            Result2 res  = new Result2(dato.location, 1); // O(1)
            stack.Push(res);                              // O(1)
        }

        return(stack.Pop()); // O(1)

        // Mi complejidad esperada en avg case es O(N)
    }
示例#28
0
        static void Main(string[] args)
        {
            // 문제 1
            //Func<int> func_1 = () => 10;
            //Func<int, int> func_2 = (a) => a * 2;

            //Console.WriteLine(func_1() + func_2(30));

            //문제 2
            int[] array = { 11, 22, 33, 44, 55 };

            //foreach (int a in array)
            //{
            //    Action action = new Action
            //        (
            //            delegate ()
            //            {
            //                Console.WriteLine(a * a);
            //            }
            //        );
            //    action.Invoke();
            //}

            // 기본 람다식
            Console.WriteLine(">> 기본 람다식 <<");
            Result re = (int a) => a * a;

            foreach (int a in array)
            {
                Console.WriteLine(re(a));
            }
            Console.WriteLine();

            // 문 형식 람다식
            Console.WriteLine(">> 문형식 람다식 <<");
            Result2 re2 = (int[] arr) =>
            {
                foreach (int a in arr)
                {
                    Console.WriteLine(a * a);
                }
            };

            re2(array);
            Console.WriteLine();

            // Func 람다식
            Console.WriteLine(">> Func 람다식 <<");
            Func <int, int> func = (x) => x * x;

            foreach (int a in array)
            {
                Console.WriteLine(func(a));
            }
            Console.WriteLine();

            // Action 람다식
            Console.WriteLine(">> Action 람다식 <<");
            Action <int[]> action = (int[] arr) =>
            {
                foreach (int a in arr)
                {
                    Console.WriteLine(a * a);
                }
            };

            action(array);
            Console.WriteLine();
        }
示例#29
0
 private Result2 <OrderUpdateResult, string[]> ToOrderUpdateResult(OrderUpdateResult result)
 {
     return(Result2 <OrderUpdateResult, string[]> .Succeeded(result));
 }
示例#30
0
 public void Run(Result1 res1, Result2 res2, Result3 res3)
 => Interlocked.Add(ref _result, res1.Data + res2.Data + res3.Data);