<commit_before># Import libraries
import os
import pandas as pd
import pyodbc
from datetime import datetime

def return_between_date_query_string(start_date, end_date):
        if start_date != None and end_date != None:
            start_end_str = '''AND [TimeStampLocal] >= '%s' AND [TimeStampLocal] < '%s' ''' %(start_date, end_date)
        elif start_date != None and end_date == None:
            start_end_str = '''AND [TimeStampLocal] >= '%s' ''' %(start_date)
        elif start_date == None and end_date != None:
            start_end_str = '''AND [TimeStampLocal] < '%s' ''' %(end_date)
        else:
            start_end_str = ''
        
        return start_end_str
    
def sql_or_string_from_mvs_ids(mvs_ids):
    or_string = ' OR '.join(['MVS_ID = {}'.format(mvs_id) for mvs_id in mvs_ids])
    return or_string

# Define DataBase class
class M2D2(object):
    '''Class to connect to standard RAG databases
    '''

    def __init__(self):
        '''Data structure for connecting to and downloading data from M2D2. Convention is::

            import anemoi as an
            m2d2 = an.io.database.M2D2()
        
        :Parameters:
        

        :Returns:

        out: an.M2D2 object connected to M2D2
        '''
        
        self.database = 'M2D2'
        server = 'sdhqragdbprd01'
        db = 'M2D2_DB_BE'
        
        conn_str = 'DRIVER={SQL Server}; SERVER=%s; DATABASE=%s; Trusted_Connection=yes' %(server, db)
        self.conn_str = conn_str #Assign connection string
        
        try:
            self.conn = pyodbc.connect(self.conn_str) #Apply connection string to connect to database
        except:
            print('Database connection error: you either don\'t have permission to the database or aren\'t signed onto the VPN')
        
    def connection_check(self, database):
        return self.database == database

    def get_masts(self):
        '''
        :Returns:

        out: DataFrame of all met masts with measured data in M2D2

        Example::

            import anemoi as an
            m2d2 = an.io.database.M2D2()
            m2d2.get_masts()

        ''' 
        
        if not self.connection_check('M2D2'):
            raise ValueError('Need to connect to M2D2 to retrieve met masts. Use anemoi.DataBase(database="M2D2")')
        
        sql_query_masts = '''
        SELECT [Project]
            ,[AssetID]
            ,[WMM_ID]
            ,[MVS_ID]
            ,[Name]
            ,[Type]
            ,[StartDate]
            ,[StopDate]
        FROM [M2D2_DB_BE].[dbo].[ViewProjectAssetSensors] WITH (NOLOCK)
        '''
        masts = pd.read_sql(sql_query_masts, self.conn)
        masts.set_index(['Project', 'WMM_ID', 'Type'], inplace=True)
        masts['StartDate'] = pd.to_datetime(masts['StartDate'], infer_datetime_format=True)
        masts['StopDate'] = pd.to_datetime(masts['StopDate'], infer_datetime_format=True)
        masts.sort_index(inplace=True)
        return masts

    def get_column_labels(self, wmm_id):<commit_msg>Lat, long to mast extract<commit_after># Import libraries
import os
import pandas as pd
import pyodbc
from datetime import datetime

def return_between_date_query_string(start_date, end_date):
        if start_date != None and end_date != None:
            start_end_str = '''AND [TimeStampLocal] >= '%s' AND [TimeStampLocal] < '%s' ''' %(start_date, end_date)
        elif start_date != None and end_date == None:
            start_end_str = '''AND [TimeStampLocal] >= '%s' ''' %(start_date)
        elif start_date == None and end_date != None:
            start_end_str = '''AND [TimeStampLocal] < '%s' ''' %(end_date)
        else:
            start_end_str = ''
        
        return start_end_str
    
def sql_or_string_from_mvs_ids(mvs_ids):
    or_string = ' OR '.join(['MVS_ID = {}'.format(mvs_id) for mvs_id in mvs_ids])
    return or_string

# Define DataBase class
class M2D2(object):
    '''Class to connect to standard RAG databases
    '''

    def __init__(self):
        '''Data structure for connecting to and downloading data from M2D2. Convention is::

            import anemoi as an
            m2d2 = an.io.database.M2D2()
        
        :Parameters:
        

        :Returns:

        out: an.M2D2 object connected to M2D2
        '''
        
        self.database = 'M2D2'
        server = 'sdhqragdbprd01'
        db = 'M2D2_DB_BE'
        
        conn_str = 'DRIVER={SQL Server}; SERVER=%s; DATABASE=%s; Trusted_Connection=yes' %(server, db)
        self.conn_str = conn_str #Assign connection string
        
        try:
            self.conn = pyodbc.connect(self.conn_str) #Apply connection string to connect to database
        except:
            print('Database connection error: you either don\'t have permission to the database or aren\'t signed onto the VPN')
        
    def connection_check(self, database):
        return self.database == database

    def get_masts(self):
        '''
        :Returns:

        out: DataFrame of all met masts with measured data in M2D2

        Example::

            import anemoi as an
            m2d2 = an.io.database.M2D2()
            m2d2.get_masts()

        ''' 
        
        if not self.connection_check('M2D2'):
            raise ValueError('Need to connect to M2D2 to retrieve met masts. Use anemoi.DataBase(database="M2D2")')
        
        sql_query_masts = '''
        SELECT [Project]
            ,[AssetID]
            ,[WMM_ID]
            ,[MVS_ID]
            ,[Name]
            ,[Type]
            ,[StartDate]
            ,[StopDate]
        FROM [M2D2_DB_BE].[dbo].[ViewProjectAssetSensors] WITH (NOLOCK)
        '''
        
        sql_query_coordinates='''
        SELECT [WMM_ID]
            ,[WMM_Latitude]
            ,[WMM_Longitude]
            ,[WMM_Elevation]
        FROM [M2D2_DB_BE].[dbo].[ViewWindDataSet]'''
        
        masts = pd.read_sql(sql_query_masts, self.conn, parse_dates=['StartDate', 'StopDate'])
        coordinates = pd.read_sql(sql_query_coordinates, self.conn)
        masts = masts.merge(coordinates, left_on='WMM_ID', right_on='WMM_ID')

        masts.set_index(['Project', 'WMM_ID', 'WMM_Latitude', 'WMM_Longitude', 'Type'], inplace=True)
        masts.sort_index(inplace=True)
        return masts

    def get_column_labels(self, wmm_id):
{'fraction_non_alphanumeric': 0.10949367088607595, 'fraction_numerical': 0.011075949367088608, 'mean_word_length': 2.2086294416243657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2718504', 'n_tokens_mistral': 2044, 'n_tokens_neox': 1986, 'n_words': 484}