<jupyter_start><jupyter_text>Create type and streams Objective load a dataset and run a pre-defined set of analysesThis set of notebooks is based upon 1. NASA bearing dataset: http://data-acoustics.com/measurements/bearing-faults/bearing-4/   Set number 2: 4 accelerometers one on each bearing2. Tutorial: https://towardsdatascience.com/machine-learning-for-anomaly-detection-and-condition-monitoring-d4614e7de770Acknowledgement is made for the measurements used in this work provided through data-acoustics.com DatabaseRequirements:1. Juptyer notebook or lab2. Python 3. ocs_sample_library https://github.com/osisoft/OSI-Samples/tree/master/ocs_samples/library_samples/Python34. config.ini configured for your OSIsoft Cloud Services environment. Example here:https://github.com/osisoft/OSI-Samples/tree/master/ocs_samples/basic_samples/SDS/Python/SDSPy/Python3  Note: Follow the instructions in the notebook '0. configure...' prior to running this notebook<jupyter_code>import configparser
import logging
from ocs_sample_library_preview import *
import json

config = configparser.ConfigParser()
config.read('config.ini')

ocsClient = OCSClient(config.get('Access', 'ApiVersion'), config.get('Access', 'Tenant'), config.get('Access', 'Resource'), 
                        config.get('Credentials', 'ClientId'), config.get('Credentials', 'ClientSecret'))
        

namespace_id = config.get('Configurations', 'Namespace')
print(namespace_id)<jupyter_output>RS-MEA<jupyter_text>Create a type and streams to describe the bearing data<jupyter_code># Dictionary to describe information about the type
thetype = {'sdstypecode': SdsTypeCode.Object, 
           'id': 'bearing',
           'name': 'bearing', 
           'description': 'bearing vibration signals'}

# sds type properties
timestamp_property = SdsTypeProperty()
timestamp_property.Id = "timestamp"
timestamp_property.SdsType = SdsType.fromDictionary({"SdsTypeCode": SdsTypeCode.DateTime.value})
timestamp_property.IsKey = True

index_property = SdsTypeProperty()
index_property.Id = "index"
index_property.SdsType = SdsType.fromDictionary({"SdsTypeCode": SdsTypeCode.Decimal.value})

channel_property =  SdsTypeProperty()
channel_property.Id = "channel"
channel_property.SdsType = SdsType.fromJson({"SdsTypeCode" : SdsTypeCode.Double.value})

# sds type defintion
bearing = SdsType()
bearing.Id = thetype['id']
bearing.SdsTypeCode = thetype['sdstypecode']
bearing.Name = thetype['name']
bearing.Description=thetype['description']
bearing.Properties = [timestamp_property,index_property,channel_property]

bearing_type = ocsClient.Types.getOrCreateType(namespace_id, bearing)
#print(json.dumps(json.loads(bearing_type.toJson()), indent=4))
# create the streams using the defined type
for bearing in range (1,5):
    stream = SdsStream(id=f'NASA.Bearing{bearing}',name=f'bearing{bearing}', description=f'Bearing {bearing} Channel 1', typeId='bearing')
    stream = ocsClient.Streams.getOrCreateStream(namespace_id,stream)
    print(f'id: {stream.Id}, name: {stream.Name}')<jupyter_output>id: NASA.Bearing1, name: bearing1
id: NASA.Bearing2, name: bearing2
id: NASA.Bearing3, name: bearing3
id: NASA.Bearing4, name: bearing4<jupyter_text>Create a type and streams to store the aggregate value for each sample<jupyter_code># Dictionary to describe information about the type
thetype = {'sdstypecode': SdsTypeCode.Object, 
           'id': 'bearing.agg',
           'name': 'bearing channel aggregate', 
           'description': 'bearing vibration signals'}

# sds type defintion
bearing = SdsType()
bearing.Id = thetype['id']
bearing.SdsTypeCode = thetype['sdstypecode']
bearing.Name = thetype['name']
bearing.Description=thetype['description']
# use previous definitions for properties
bearing.Properties = [timestamp_property,channel_property]

bearing_type = ocsClient.Types.getOrCreateType(namespace_id, bearing)
#print(json.dumps(json.loads(bearing_type.toJson()), indent=4))
# create the streams using the defined type
for bearing in range (1,5):
    stream = SdsStream(id=f'NASA.Bearing{bearing}.agg',name=f'bearing{bearing} aggregate', description=f'Bearing {bearing} Channel 1', typeId='bearing.agg')
    ocsClient.Streams.createOrUpdateStream(namespace_id,stream)
    print(f'id: {stream.Id}, name: {stream.Name}')<jupyter_output>id: NASA.Bearing1.agg, name: bearing1 aggregate
id: NASA.Bearing2.agg, name: bearing2 aggregate
id: NASA.Bearing3.agg, name: bearing3 aggregate
id: NASA.Bearing4.agg, name: bearing4 aggregate
{'fraction_non_alphanumeric': 0.115916183682568, 'fraction_numerical': 0.00980829246544806, 'mean_word_length': 6.066141732283465, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '483721', 'license': 'Apache-2.0', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1354, 'n_words': 320, 'path': 'Appendix 1. create types and streams.ipynb', 'repo_name': 'careylipu/nasa_bearing', 'size': '4486'}