Stores an entire column of graph metric values, where the values are mapped to the next worksheet row.
The graph metric value returned by GraphMetricValuesOrdered should be written to the worksheet rows in sequential row order -- the first value in the first row, the second value in the second row, and so on.
Inheritance: GraphMetricColumn
    FilterAndReformatWordMetrics
    (
        ref Int32 iTableIndex,
        String sTableDescription,
        GraphMetricColumnOrdered oWord1Column,
        GraphMetricColumnOrdered oWord2Column,
        GraphMetricColumnOrdered oCountColumn,
        GraphMetricColumnOrdered oGroupNameColumn,
        List<GroupEdgeInfo> oAllGroupEdgeInfos,
        String sGroupTableColumnName,
        List<GraphMetricColumn> oGraphMetricColumns
    )
    {
        Debug.Assert(iTableIndex >= 1);
        Debug.Assert( !String.IsNullOrEmpty(sTableDescription) );
        Debug.Assert(oWord1Column != null);
        // oWord2Column
        Debug.Assert(oCountColumn != null);
        Debug.Assert(oGroupNameColumn != null);
        Debug.Assert(oAllGroupEdgeInfos != null);
        Debug.Assert( !String.IsNullOrEmpty(sGroupTableColumnName) );
        Debug.Assert(oGraphMetricColumns != null);
        AssertValid();

        Boolean bIsForWords = (oWord2Column == null);

        GraphMetricValueOrdered [] aoWord1Values =
            oWord1Column.GraphMetricValuesOrdered;

        GraphMetricValueOrdered [] aoWord2Values = null;

        if (!bIsForWords)
        {
            aoWord2Values = oWord2Column.GraphMetricValuesOrdered;
        }

        GraphMetricValueOrdered [] aoCountValues =
            oCountColumn.GraphMetricValuesOrdered;

        GraphMetricValueOrdered [] aoGroupNameValues =
            oGroupNameColumn.GraphMetricValuesOrdered;

        List<GraphMetricValueWithID> oTopWordsOrWordPairsForGroupWorksheet =
            new List<GraphMetricValueWithID>();

        // The key is a group name from the word or word pair table created by
        // WordMetricCalculator2 and the value is the index of the first row
        // for that group.

        Dictionary<String, Int32> oGroupNameIndexes =
            TwitterSearchNetworkWordMetricUtil
            .GetGroupNameIndexesFromWordMetrics(aoGroupNameValues);

        Int32 iGroups = oAllGroupEdgeInfos.Count;
        String sTableName = GetTableName(ref iTableIndex);

        for (Int32 iGroup = 0; iGroup < iGroups; iGroup++)
        {
            GroupEdgeInfo oGroupEdgeInfo = oAllGroupEdgeInfos[iGroup];

            // Populate GraphMetricValueOrdered collections with the top words
            // or word pairs and their counts for this group.

            List<GraphMetricValueOrdered> oTopWordsOrWordPairs =
                new List<GraphMetricValueOrdered>();

            List<GraphMetricValueOrdered> oTopCounts =
                new List<GraphMetricValueOrdered>();

            String sGroupName = GetGroupName(oGroupEdgeInfo);

            String sGroupNameOrDummyGroupName =
                sGroupName ?? GroupEdgeSorter.DummyGroupNameForEntireGraph;

            Int32 iFirstRowForGroup;

            if ( oGroupNameIndexes.TryGetValue(sGroupNameOrDummyGroupName,
                out iFirstRowForGroup) )
            {
                TwitterSearchNetworkWordMetricUtil.CopyWordMetricsForGroup(
                    sGroupNameOrDummyGroupName, aoWord1Values, aoWord2Values,
                    aoCountValues, aoGroupNameValues, iFirstRowForGroup,
                    MaximumTopItems, oTopWordsOrWordPairs, oTopCounts);
            }

            // (The extra "1" is for the dummy group that represents the entire
            // graph.)

            if (iGroup < MaximumTopGroups + 1)
            {
                String sGraphMetricColumn1Name, sGraphMetricColumn2Name;

                GetGraphMetricColumnNames(sTableDescription, sGroupName,
                    out sGraphMetricColumn1Name, out sGraphMetricColumn2Name);

                AddGraphMetricColumnPair(sTableName, sGraphMetricColumn1Name,
                    sGraphMetricColumn2Name, oTopWordsOrWordPairs, oTopCounts,
                    false, oGraphMetricColumns);
            }

            if (oGroupEdgeInfo.GroupInfo != null)
            {
                // This is a real group, not the dummy group.  Add a cell for
                // the column on the group worksheet.

                oTopWordsOrWordPairsForGroupWorksheet.Add(
                    new GraphMetricValueWithID(
                        GetGroupRowID(oGroupEdgeInfo),

                        ExcelUtil.ForceCellText(
                            TwitterSearchNetworkWordMetricUtil
                            .ConcatenateTopWordsOrWordPairs(
                                oTopWordsOrWordPairs, bIsForWords,
                                MaximumTopItems) )
                    ) );
            }
        }

        oGraphMetricColumns.Add( new GraphMetricColumnWithID(
            WorksheetNames.Groups, TableNames.Groups, sGroupTableColumnName,
            ExcelTableUtil.AutoColumnWidth, null, null,
            oTopWordsOrWordPairsForGroupWorksheet.ToArray() ) );
    }
コード例 #2
0
    WriteGraphMetricColumnOrderedToWorkbook
    (
        GraphMetricColumnOrdered oGraphMetricColumnOrdered,
        ListObject oTable
    )
    {
        Debug.Assert(oGraphMetricColumnOrdered != null);
        Debug.Assert(oTable != null);
        AssertValid();

        GraphMetricValueOrdered [] aoGraphMetricValuesOrdered =
            oGraphMetricColumnOrdered.GraphMetricValuesOrdered;

        Int32 iRows = aoGraphMetricValuesOrdered.Length;

        // Make sure the table has enough rows.

        ResizeTable(oTable, iRows);

        Range oVisibleColumnData;

        // Get the specified column.

        if ( !TryGetRequiredColumnInformation(oGraphMetricColumnOrdered,
            oTable, out oVisibleColumnData) )
        {
            return;
        }

        // Copy the graph metric values to an array.

        Object [,] aoValues = ExcelUtil.GetSingleColumn2DArray(iRows);
        Boolean bStyleSpecified = false;

        for (Int32 i = 0; i < iRows; i++)
        {
            GraphMetricValueOrdered oGraphMetricValueOrdered =
                aoGraphMetricValuesOrdered[i];

            aoValues[i + 1, 1] = oGraphMetricValueOrdered.Value;

            if (oGraphMetricValueOrdered.Style != null)
            {
                // A style was specified for this row.  It will need to be
                // applied later.  (It should be possible to apply the style
                // here, but that does not work reliably when values are
                // written to the cells afterwards, as they are after this
                // loop.)

                bStyleSpecified = true;
            }
        }

        // Write the array to the column.

        Range oWrittenRange = ExcelUtil.SetRangeValues(
            oVisibleColumnData, aoValues);

        if (oGraphMetricColumnOrdered.ConvertUrlsToHyperlinks)
        {
            ExcelUtil.ConvertUrlsToHyperlinks(oWrittenRange);
        }

        if (bStyleSpecified)
        {
            for (Int32 i = 0; i < iRows; i++)
            {
                String sStyle = aoGraphMetricValuesOrdered[i].Style;

                if (sStyle != null)
                {
                    // This row has a style.  Apply it.

                    ExcelUtil.SetRangeStyle(
                        (Range)oVisibleColumnData.Cells[i + 1, 1], sStyle);
                }
            }
        }
    }