import fmrest
from pandas.plotting import parallel_coordinates
from matplotlib import pyplot as plt
%matplotlib inline

"""
Explanation: Turning python-fmrest foundset into DataFrame
This is a short example on how to easily build a Pandas DataFrame from a Foundset.
Here you can find information about Pandas and DataFrames and how you can work with these data structures when analysing data.
For this example, make sure to first install Pandas (pip install pandas) and optionally Matplotlib (pip install matplotlib).
End of explanation
"""


fms = fmrest.Server('https://10.211.55.15',
                    user='admin',
                    password='admin',
                    database='Contacts',
                    layout='Iris',
                    verify_ssl=False,
                    #type_conversion=True #Danger!
                   )

fms.login()

"""
Explanation: Create server instance and login
First, we create our server instance just like in the examples before.
End of explanation
"""


foundset = fms.get_records(limit=150)
foundset

"""
Explanation: If you have numbers in text fields or want to work with dates, you can try out type_conversion=True.
Note: As this "type-guessing" can, at times, lead to unexpected results, I strongly recommended you to do the type conversion yourself when working with your own "known" data fields.
Fetch records from server
Let's fetch all data from our Iris layout as specified above.
(When you have more than 100 records to fetch, make sure to specify the limit parameter as the Data API defaults to 100 records.)
End of explanation
"""


df = foundset.to_df()
df.head()

"""
Explanation: Turn foundset into DataFrame
Now that we have our Foundset instance, the only thing we need to do is to call the to_df method. This will give us a Pandas DataFrame.
Let's look at the first 5 rows.
End of explanation
"""


df.drop(['recordId', 'modId'], axis=1, inplace=True)
df.head()

"""
Explanation: Since we are not interested in recordId or modId, we just drop them.
End of explanation
"""


df.dtypes

"""
Explanation: Before working with your data, check that the types are OK (previous versions of the Data API always returned strings and ignored the data type set in your DB schema).
End of explanation
"""


plt.figure(figsize=(12, 12))
parallel_coordinates(df, 'class')

"""
Explanation: Going from here
With your DataFrame ready, you can go on analyzing and plotting your data as you wish...
End of explanation
"""


