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();
            }
        }
Exemple #2
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleRow printDelimiter
        public static void print()
        {
            const String input = "Socialism,Communism,Fascism";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.parseCsv();
                p.print("Failed Systems: $1, $2, and $3");
                p.writeStdout();
            }
            // outputs: Failed Systems: Socialism, Communism, and Fascism
        }
Exemple #3
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleLine parseDelimiter
        public static void parseDelimiter()
        {
            const String input = "a|b|c|d|e|f|g";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.sed("[aceg]", @"\0\0", "gi");     // duplicates every other char
                p.parseDelimiter("|");
                p.print("$1,$3,$5,$7|$2,$4,$6");
                p.writeStdout();
            }
            // outputs: aa,cc,ee,gg|b,d,f
        }
Exemple #4
0
        public void printLine()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString("Logic");
                p.print("$0 $0");
                actual = p.processToString();
            }

            const String expected = "Logic Logic";

            Assert.Equal(expected, actual);
        }
Exemple #5
0
        public void printRow()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.parseCsv();
                p.print("$3,$2,$1");
                actual = p.processToString();
            }

            const String expected = "Mother goddess of the earth,Terra,Gaia";

            Assert.Equal(expected, actual);
        }
Exemple #6
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleLine embeddedNewlineParseCsv
        public static void embeddedNewlineParseCsv()
        {
            const String input = "a,\"Long\nText\n\"";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);          // StreamToLineProcessor
                p.print("$0");                // forces line state
                p.parseCsv(strict: false);
                p.selectColumns(2, 1);
                p.writeStdout();
            }
            // outputs:
            // Long,a
            // ,Text
            // ,
        }
Exemple #7
0
        public static int main()
        {
            using (Pnyx p = new Pnyx())
            {
                p.read(@"c:/dev/asclepius/prod_import/events.csv");
                p.grep("CL/C/MonitoringDashboard/");
                p.sed("MonitoringDashboard[/][^.]+[.]", "MonitoringDashboard.");
                p.sed("CL/C/MonitoringDashboard.", "");
                p.parseCsv();
                p.withColumns(p2 => { p2.sed(",", "", "g"); }, 2, 3);
                p.lineTransformerFunc(line => TextUtil.encodeSqlValue(line));
                p.print("insert into `groupit` values($1,$2);");
                p.write(@"c:/dev/asclepius/prod_import/events.sql");
            }

            return(0);
        }
Exemple #8
0
 // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleStateMachine teeMultiple
 public static void teeMultiple()
 {
     using (Pnyx p = new Pnyx())
     {
         p.readString("clientId: 123456\n");
         p.tee(p2 =>
         {
             p2.write("copy.txt");
             // outputs: clientId: 123456
         });
         p.parseDelimiter(": ");
         p.selectColumns(2);
         p.tee(p2 =>
         {
             p2.write("ids.txt");
             // outputs: 123456
         });
         p.print("delete from client where id = $0;");
         p.writeStdout();
         // outputs: delete from client where id = 123456;
     }
 }
Exemple #9
0
        public static int main()
        {
            using (Pnyx p = new Pnyx())
            {
                p.read("nya.csv");
                p.parseCsv();
                p.rowTransformerFunc(row =>
                {
                    var fullName = row[1];

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

                    return(pnyx.net.util.RowUtil.replaceColumn(row, 2, name.firstName, name.lastName));
                });
                p.selectColumns(2, 3, 5);
                p.columnTransformer(3, new pnyx.net.impl.DateTransform {
                    formatSource = "M-d-yyyy", formatDestination = "yyyy-M-d"
                });
                p.lineTransformerFunc(x => pnyx.net.util.TextUtil.encodeSqlValue(x));
                p.print("insert into tmp_name values($1,$2,$3);");
                p.write("nya.sql");
            }

            using (Pnyx p = new Pnyx())
            {
                p.read(@"C:\dev\asclepius\prod_import\alt.txt");
                p.parseTab();
                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.middleName, name.lastName));
                });
                p.lineTransformerFunc(x => pnyx.net.util.TextUtil.encodeSqlValue(x));
                p.sortRow(new[] { 1, 3 });
                p.writeCsv(@"C:\dev\asclepius\prod_import\alt.csv");
            }

            using (Pnyx p = new Pnyx())
            {
                p.read(@"C:\dev\asclepius\prod_import\alt_names.csv");
                p.parseCsv();
                p.columnTransformer(3, new DateTransform {
                    formatSource = DateUtil.FORMAT_MDYYYY, formatDestination = DateUtil.FORMAT_ISO_8601_DATE
                });
                p.rowTransformerFunc(row =>
                {
                    for (int i = 0; i < row.Count; i++)
                    {
                        row[i] = TextUtil.encodeSqlValue(row[i]);
                    }
                    return(row);
                });
                p.print("insert into to_import value($1,$2,$3);");
                p.write(@"C:\dev\asclepius\prod_import\names.sql");
            }

            return(0);
        }