OHLC time series resampler.
        
        Resamples time series data to create Open-Hi-Lo-Close (OHLC) data,
        which can be useful for statistical tests, or simply for charting.

        Frequency abbreviations are taken from the pandas library.  By
        default, this method does daily ("D") resampling.

def resample_time_series(self):
        """OHLC time series resampler.
        
        Resamples time series data to create Open-Hi-Lo-Close (OHLC) data,
        which can be useful for statistical tests, or simply for charting.

        Frequency abbreviations are taken from the pandas library.  By
        default, this method does daily ("D") resampling.

        """
        with cursor() as cur:
            cur.execute("SELECT max(starttime) FROM resampled_ledger")
            if cur.rowcount:
                last_resample = str(cur.fetchone()[0])
            else:
                last_resample = 0
            if not self.quiet:
                print("Resampling time series...")
            for market in self.markets:
                sys.stdout.write(market[0] + "-" + market[1] + "\r")
                sys.stdout.flush()

                # Resample all transactions
                if self.full or last_resample == 'None':
                    query = (
                        "SELECT currency1, currency2, price1, price2, "
                        "amount1, amount2, txdate FROM ripple_ledger "
                        "WHERE market = '%s' "
                        "ORDER BY txdate"
                    ) % (market[0] + market[1])

                # Resample transactions from the last resampling
                # starting timestamp or newer
                else:
                    query = (
                        "SELECT currency1, currency2, price1, price2, "
                        "amount1, amount2, txdate FROM ripple_ledger "
                        "WHERE market = '%s' AND txdate >= '%s' "
                        "ORDER BY txdate"
                    ) % (market[0] + market[1], last_resample)
                df = psql.frame_query(query, conn)
                if not df.empty:
                    for f in self.resampling_frequencies:
                        rs = self.resampler(df, freq=f)
                        self.write_resampled(rs, market, cur, freq=f)
                    conn.commit()
            print()
            print(self.updates, "resampled_ledger records updated")
            print()

        # Index the columns: starttime, freq, currency1, currency2
        conn.set_isolation_level(ext.ISOLATION_LEVEL_AUTOCOMMIT)
        with cursor() as cur:
            if not self.quiet:
                print("Indexing...")
            idx_queries = (
                "DROP INDEX IF EXISTS idx_ledger_interval",
                (
                    "CREATE INDEX CONCURRENTLY idx_ledger_interval ON "
                    "resampled_ledger(starttime, freq, currency1, currency2)"
                ),
            )
            for query in idx_queries:
                cur.execute(query)