Пример #1
0
        private static void ccmNames()
        {
            using (Pnyx p = new Pnyx())
            {
                p.read("C:/dev/asclepius/prod_import/ccm_names.csv");
                p.parseCsv(hasHeader: true);
                p.rowTransformerFunc(row =>
                {
                    String lastName = row[1];
                    Tuple <String, String> lastNameSuffix = NameUtil.parseSuffix(lastName);

                    if (lastNameSuffix.Item2 == null)
                    {
                        return(null);
                    }

                    // Expands name into 2 columns
                    row = RowUtil.replaceColumn(row, 2, lastNameSuffix.Item1, lastNameSuffix.Item2);
                    return(row);
                });
                p.rowTransformerFunc(row =>
                {
                    for (int i = 0; i < row.Count; i++)
                    {
                        row[i] = TextUtil.encodeSqlValue(row[i]);
                    }
                    return(row);
                });
                p.print("update bhc_patient_ccm set lastname=$2, suffix=$3 where patientid=$1;");
                p.write("C:/dev/asclepius/prod_import/ccm_names_update.sql");
                p.process();
            }
        }
Пример #2
0
        public void explicitArgs(int argCount, int?readArg, int?writeArg, String error)
        {
            String inPath  = Path.Combine(TestUtil.findTestFileLocation(), "encoding", "psalm23.unix.ansi.txt");
            String outPath = Path.Combine(TestUtil.findTestOutputLocation(), "argsOutput", Guid.NewGuid() + ".txt");

            FileUtil.assureDirectoryStructExists(outPath);

            String[] args;
            switch (argCount)
            {
            default: args = new string[0]; break;

            case 1: args = new [] { inPath }; break;

            case 2: args = new [] { inPath, outPath }; break;

            case 3: args = new [] { inPath, outPath, "junk" }; break;
            }
            ArgsInputOutput numbered = new ArgsInputOutput(args);

            using (Pnyx p = new Pnyx())
            {
                p.setSettings(processOnDispose: false);
                p.setNumberedInputOutput(numbered);

                try
                {
                    if (readArg == null)
                    {
                        p.read(inPath);
                    }
                    else
                    {
                        p.readArg(readArg.Value);
                    }

                    if (writeArg == null)
                    {
                        p.write(outPath);
                    }
                    else
                    {
                        p.writeArg(writeArg.Value);
                    }

                    p.compile();

                    Assert.Null(error);
                }
                catch (Exception err)
                {
                    Assert.Equal(error, err.Message);
                    return;
                }

                p.process();
            }

            Assert.Null(TestUtil.binaryDiff(inPath, outPath));
        }
Пример #3
0
        private static void transform()
        {
            using (Pnyx p = new Pnyx())
            {
                p.read("C:/dev/asclepius/prod_import/BHC Patients from 1-1-15 thru 10-31-2018.csv");
                p.parseCsv(hasHeader: true);
                p.withColumns(p2 => p2.lineTransformer(new DateTransform
                {
                    formatSource = DateUtil.FORMAT_MDYYYY, formatDestination = DateUtil.FORMAT_ISO_8601_DATE
                }), 4, 5, 6);
                p.rowTransformerFunc(row =>
                {
                    String fullName = row[2];

                    Name name = NameUtil.parseFullName(fullName);
                    if (name == null)
                    {
                        return(null);
                    }

                    // Expands name into 4 columns
                    row = RowUtil.replaceColumn(row, 3, name.firstName, name.middleName, name.lastName, name.suffix);
                    return(row);
                });
                p.tee(p2 =>
                {
                    p2.removeColumns(7 + 3, 8 + 3, 9 + 3);                // plus 3 from name split above
                    p2.rowFilter(new RepeatFilter());
                    p2.write("C:/dev/asclepius/prod_import/bhc_discharges.csv");
                });
                p.widthColumns(9 + 3);                                  // plus 3 from name split above
                p.write("C:/dev/asclepius/prod_import/bhc_discharges_diagnosis.csv");
                p.process();
            }
        }
Пример #4
0
        private static void transform()
        {
            using (Pnyx p = new Pnyx())
            {
                p.setSettings(outputNewline: "\n");

                p.read("C:/dev/asclepius/prod_import/bhc_procedures.csv");
                p.parseCsv(hasHeader: true);
                p.withColumns(p2 => p2.lineTransformer(new DateTransform
                {
                    formatSource = DateUtil.FORMAT_MDYYYY, formatDestination = DateUtil.FORMAT_ISO_8601_DATE
                }), 12);
                p.rowTransformer(new DateFixer());
                p.tee(p2 =>
                {
                    p2.removeColumns(7, 8, 9, 10, 11);
                    p2.withColumns(p3 => p3.rowFilter(new RepeatFilter()), 1, 2, 7);
                    p2.write("C:/dev/asclepius/prod_import/bhc_procedure_base.csv");
                });
                p.removeColumns(3, 4, 5, 6);
                p.rowTransformer(new SequenceFixer());
                p.write("C:/dev/asclepius/prod_import/bhc_procedure_diagnosis.csv");
                p.process();
            }
        }
Пример #5
0
 private static void columnDefs()
 {
     using (Pnyx p = new Pnyx())
     {
         p.read("C:/dev/asclepius/prod_import/bhc_procedures.csv");
         p.parseCsv();
         p.columnDefinition(maxWidth: true, hasHeaderRow: true, minWidth: true, nullable: true);
         p.swapColumnsAndRows();
         p.writeStdout();
         p.process();
     }
 }
Пример #6
0
 public static void helloWorld()
 {
     using (Pnyx p = new Pnyx())
     {
         p.readString("Hello World.");
         p.sed("World", "World, with love from Pnyx.."); // transforms each line
         p.grep("world", caseSensitive: false);          // filters each line
         p.writeStdout();
         p.compile();                                    // Builds processors and wires filters together
         p.process();                                    // Runs processors (All IO is done here)
     }
     // outputs: Hello World, with love from Pnyx...
 }
Пример #7
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleSettings instance
        public static void instance()
        {
            const String input = "line one\nline two";

            using (Pnyx p = new Pnyx())
            {
                p.setSettings(stdIoDefault: true);
                p.readString(input);
                p.process(); // automatically writes to STD-OUT
            }
            // outputs STD-OUT:
            // line one
            // line two
        }
Пример #8
0
        public void teeServile()
        {
            MemoryStream capture = new MemoryStream();

            Pnyx teeP = null;
            Pnyx p    = new Pnyx();

            p.readString(PLANETS_GODS_TITANS);
            p.tee(pn =>
            {
                teeP = pn;
                pn.writeStream(capture);
            });

            Assert.Equal(FluentState.CompiledServile, teeP.state);
            Assert.Throws <IllegalStateException>(() => teeP.process());
        }
Пример #9
0
        private static int runCSharp(Dictionary <String, String> switches, String[] args)
        {
            String source;

            if (switches.hasAny("-i", "--inline"))
            {
                if (args.Length == 0)
                {
                    return(printUsage("missing inline CSharp script", 3));
                }

                source = args[0];
            }
            else
            {
                if (args.Length == 0)
                {
                    return(printUsage("missing CSharp file", 2));
                }

                using (TextReader reader = new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read)))
                    source = reader.ReadToEnd();
            }

            Pnyx p = new Pnyx();

            p.setSettings(stdIoDefault: true);              // forces STD-IN/OUT as defaults

            // Sets arguments
            args = args.Skip(1).ToArray();
            p.setNumberedInputOutput(new ArgsInputOutput(args));

            CodeParser parser = new CodeParser();

            parser.parseCode(p, source, compilePnyx: true);
            if (p.state != FluentState.Compiled)
            {
                throw new IllegalStateException("Pnyx wasn't compiled properly");
            }

            using (p)
                p.process();

            return(0);
        }
Пример #10
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleSettings global
        public static void global()
        {
            SettingsHome.settingsFactory = new SettingsHome(
                new Settings
            {
                stdIoDefault = true      // turns on globally
            });

            const String input = "line one\nline two";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.process(); // automatically writes to STD-OUT
            }
            // outputs STD-OUT:
            // line one
            // line two
        }
Пример #11
0
        private void verifyEncoding(String file, String expectedEncoding)
        {
            String inPath  = Path.Combine(TestUtil.findTestFileLocation(), "encoding", file);
            String outPath = Path.Combine(TestUtil.findTestOutputLocation(), "encoding", file);

            FileUtil.assureDirectoryStructExists(outPath);

            using (Pnyx p = new Pnyx())
            {
                p.read(inPath);
                p.write(outPath);
                p.process();

                String actualEncoding = String.Format("{0}-{1}", p.streamInformation.streamEncoding.WebName, p.streamInformation.retrieveStreamNewLineEnum().ToString());
                Assert.Equal(expectedEncoding, actualEncoding);
            }

            Assert.Null(TestUtil.binaryDiff(inPath, outPath));
        }
Пример #12
0
        public static int fix()
        {
            using (Pnyx p = new Pnyx())
            {
                p.setSettings(outputNewline: "\n");

                p.read("C:/dev/asclepius/prod_import/mirPatients.csv");
                p.parseCsv(hasHeader: false);
                p.widthColumns(10, null);
                p.rowTransformerFunc(x => new System.Collections.Generic.List <string> {
                    x[1], x[4], x[5], x[9] ?? x[8] ?? x[7] ?? x[6] ?? x[5] ?? x[4]
                });
                p.rowTransformerFunc(row =>
                {
                    var fullName = row[0];

                    var name = pnyx.net.util.NameUtil.parseFullName(fullName);
                    if (name == null)
                    {
                        return(null);
                    }

                    return(pnyx.net.util.RowUtil.replaceColumn(row, 1, name.firstName, name.lastName));
                });
                p.rowTransformerFunc(x =>
                {
                    x[2] = PhoneUtil.parsePhone(x[2]);
                    x[3] = PhoneUtil.parsePhone(x[3]);
                    return(x.ToList());
                });

                p.tee(px => px.writeStdout());
                p.write("C:/dev/asclepius/prod_import/mirPatients.out.csv");
                p.process();
            }

            return(0);
        }
Пример #13
0
        public void sort(String source, bool hasHeader, bool descending, bool caseSensitive, bool unique, String expected)
        {
            String inPath  = Path.Combine(TestUtil.findTestFileLocation(), "csv", source);
            String outPath = Path.Combine(TestUtil.findTestOutputLocation(), "csv", "line_" + expected);

            FileUtil.assureDirectoryStructExists(outPath);

            using (Pnyx p = new Pnyx())
            {
                p.read(inPath);
                if (hasHeader)
                {
                    p.lineFilter(new SkipSpecificFilter(1));
                }
                p.sort(descending, caseSensitive, unique, tempDirectory: Path.Combine(TestUtil.findTestOutputLocation(), "csv"));
                p.write(outPath);
                p.process();
            }

            String expectedPath = Path.Combine(TestUtil.findTestFileLocation(), "csv", expected);

            Assert.Null(TestUtil.binaryDiff(expectedPath, outPath));
        }