<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Our robustness data is not pickled as an ordered dictionary (collections.OrderedDict), we go ahead and convert it to one.
Step3:  Now, we can define some utility functions in order to format timestamps and percentages to be used for keys in the robustness dictionary.
Step5:  The robustness_over_time function takes an attack type and a percentage as an argument, and returns a list of robustness measurements over time.
Step6:  We are now ready to plot some data.  We'll plot the size of the gigantic component at removal rates of $0$, $0.01$, $0.03$, and $0.1$.
<ASSISTANT_TASK:>
Python Code:
import pickle
from collections import OrderedDict
import datetime
with open('robustness.pickle', 'rb') as handle:
    robustness = pickle.load(handle)
    robustness = OrderedDict({
        attack_type: {
            timestamp: OrderedDict(result)
            for timestamp, result in sorted(timestamped_results.items())
        } for attack_type, timestamped_results in sorted(robustness.items())
    })
Explanation: Our robustness data is not pickled as an ordered dictionary (collections.OrderedDict), we go ahead and convert it to one.
End of explanation
def format_percentage(percentage):
    Format a percentage appropriately.
    return "{:.3f}".format(percentage)
def format_timestamp(timestamp):
    Format a timestamp appropriately.
    return timestamp.strftime("%Y-%m")
Explanation: Now, we can define some utility functions in order to format timestamps and percentages to be used for keys in the robustness dictionary.
End of explanation
def robustness_over_time(attack_type, percentage):
    Retrieve robustness data at a given percentage of removed nodes.
    global robustness
    data = robustness[attack_type]
    return {timestamp: measurement[format_percentage(percentage)]
            for timestamp, measurement in data.items()}
Explanation: The robustness_over_time function takes an attack type and a percentage as an argument, and returns a list of robustness measurements over time.
End of explanation
fig, ax = plt.subplots()
ax.set_title("Targeted attack")
def _get_data(attack_type, percentage):
    data = robustness_over_time(attack_type, percentage)
    return (list(map(lambda timestamp: datetime.datetime.strptime(timestamp, "%Y-%m"), data.keys())),
            list(map(lambda measurement: measurement[1], data.values())))
percentages = [0, 0.01, 0.03, 0.1]
for percentage in percentages:
    ax.plot(*_get_data('targeted', percentage))
    
ax.legend(percentages)
fig, ax = plt.subplots()
ax.set_title("Random attack")
for percentage in percentages:
    ax.plot(*_get_data('random', percentage))
Explanation: We are now ready to plot some data.  We'll plot the size of the gigantic component at removal rates of $0$, $0.01$, $0.03$, and $0.1$.
End of explanation
<END_TASK>