def DurfeeSquare_metric(bpmn_graph):
all_types_count = Counter([node[<NUM_LIT:1>]['<STR_LIT:type>'] for node in bpmn_graph.get_nodes() if node[<NUM_LIT:1>]['<STR_LIT:type>']])<EOL>length = len(all_types_count)<EOL>histogram = [<NUM_LIT:0>] * (length + <NUM_LIT:1>)<EOL>for _, count in all_types_count.items():<EOL><INDENT>histogram[min(count, length)] += <NUM_LIT:1><EOL><DEDENT>sum_ = <NUM_LIT:0><EOL>for i, count in reversed(list(enumerate(histogram))):<EOL><INDENT>sum_ += count<EOL>if sum_ >= i:<EOL><INDENT>return i<EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL>
Returns the value of the Durfee Square metric
 ("Durfee Square equals d if there are d types of elements
 which occur at least d times in the model (each),
 and the other types of elements occur no more than d times (each)")
 for the BPMNDiagramGraph instance.

:param bpmn_graph: an instance of BpmnDiagramGraph representing BPMN model.